Merge "temporary fix about pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo" into tizen
[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         pkgmgr_appinfo_x *tmp;
32
33         while (info != NULL) {
34                 tmp = info->next;
35                 if (info->package)
36                         free((void *)info->package);
37                 if (info->locale)
38                         free((void *)info->locale);
39
40                 pkgmgrinfo_basic_free_application(info->app_info);
41                 free((void *)info);
42                 info = tmp;
43         }
44         return;
45 }
46
47 static char *_get_filtered_query(const char *query_raw,
48                 pkgmgrinfo_filter_x *filter)
49 {
50         char buf[MAX_QUERY_LEN] = { 0, };
51         char *condition;
52         size_t len;
53         GSList *list;
54         GSList *head = NULL;
55
56         if (filter)
57                 head = filter->list;
58
59         strncat(buf, query_raw, MAX_QUERY_LEN - 1);
60         len = strlen(buf);
61         for (list = head; list; list = list->next) {
62                 /* TODO: revise condition getter function */
63                 __get_filter_condition(list->data, &condition);
64                 if (condition == NULL)
65                         continue;
66                 if (buf[strlen(query_raw)] == '\0') {
67                         len += strlen(" WHERE ");
68                         strncat(buf, " WHERE ", MAX_QUERY_LEN - len - 1);
69                 } else {
70                         len += strlen(" AND ");
71                         strncat(buf, " AND ", MAX_QUERY_LEN -len - 1);
72                 }
73                 len += strlen(condition);
74                 strncat(buf, condition, sizeof(buf) - len - 1);
75                 free(condition);
76                 condition = NULL;
77         }
78
79         return strdup(buf);
80 }
81
82 static gint __list_strcmp(gconstpointer a, gconstpointer b)
83 {
84         return strcmp((char *)a, (char *)b);
85 }
86
87 static gint _appinfo_get_list(sqlite3 *db, const char *locale,
88                 pkgmgrinfo_filter_x *filter, GList **list)
89 {
90         static const char query_raw[] =
91                 "SELECT DISTINCT package_app_info.app_id FROM package_app_info"
92                 " LEFT OUTER JOIN package_app_localized_info"
93                 "  ON package_app_info.app_id=package_app_localized_info.app_id"
94                 "  AND package_app_localized_info.app_locale=%Q"
95                 " LEFT OUTER JOIN package_app_app_category"
96                 "  ON package_app_info.app_id=package_app_app_category.app_id"
97                 " LEFT OUTER JOIN package_app_app_control"
98                 "  ON package_app_info.app_id=package_app_app_control.app_id"
99                 " LEFT OUTER JOIN package_app_app_metadata"
100                 "  ON package_app_info.app_id=package_app_app_metadata.app_id ";
101         int ret;
102         char *query;
103         char *query_localized;
104         sqlite3_stmt *stmt;
105         char *appid = NULL;
106
107         query = _get_filtered_query(query_raw, filter);
108         if (query == NULL)
109                 return PMINFO_R_ERROR;
110         query_localized = sqlite3_mprintf(query, locale);
111         free(query);
112         if (query_localized == NULL)
113                 return PMINFO_R_ERROR;
114
115         ret = sqlite3_prepare_v2(db, query_localized,
116                         strlen(query_localized), &stmt, NULL);
117         sqlite3_free(query_localized);
118         if (ret != SQLITE_OK) {
119                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
120                 return PMINFO_R_ERROR;
121         }
122
123         while (sqlite3_step(stmt) == SQLITE_ROW) {
124                 _save_column_str(stmt, 0, (const char **)&appid);
125                 if (appid != NULL)
126                         *list = g_list_insert_sorted(*list, appid,
127                                         __list_strcmp);
128         }
129
130         sqlite3_finalize(stmt);
131
132         return PMINFO_R_OK;
133 }
134
135 static int _appinfo_get_filtered_list(pkgmgrinfo_filter_x *filter, uid_t uid,
136                 GList **list)
137 {
138         int ret;
139         sqlite3 *db;
140         const char *dbpath;
141         char *locale;
142         GList *tmp;
143         GList *tmp2;
144
145         locale = _get_system_locale();
146         if (locale == NULL)
147                 return PMINFO_R_ERROR;
148
149         dbpath = getUserPkgParserDBPathUID(uid);
150         if (dbpath == NULL) {
151                 free(locale);
152                 return PMINFO_R_ERROR;
153         }
154
155         ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
156         if (ret != SQLITE_OK) {
157                 _LOGE("failed to open db: %d", ret);
158                 free(locale);
159                 return PMINFO_R_ERROR;
160         }
161
162         if (_appinfo_get_list(db, locale, filter, list)) {
163                 free(locale);
164                 sqlite3_close_v2(db);
165                 return PMINFO_R_ERROR;
166         }
167         sqlite3_close_v2(db);
168
169         if (uid == GLOBAL_USER) {
170                 free(locale);
171                 return PMINFO_R_OK;
172         }
173
174         /* search again from global */
175         dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
176         if (dbpath == NULL) {
177                 free(locale);
178                 return PMINFO_R_ERROR;
179         }
180
181         ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
182         if (ret != SQLITE_OK) {
183                 _LOGE("failed to open db: %d", ret);
184                 free(locale);
185                 return PMINFO_R_ERROR;
186         }
187
188         if (_appinfo_get_list(db, locale, filter, list)) {
189                 free(locale);
190                 sqlite3_close_v2(db);
191                 return PMINFO_R_ERROR;
192         }
193         sqlite3_close_v2(db);
194
195         /* remove duplicate element:
196          * since the list is sorted, we can remove duplicates in linear time
197          */
198         for (tmp = *list, tmp2 = g_list_next(tmp); tmp;
199                         tmp = tmp2, tmp2 = g_list_next(tmp)) {
200                 if (tmp->prev == NULL || tmp->data == NULL)
201                         continue;
202                 if (strcmp((const char *)tmp->prev->data,
203                                         (const char *)tmp->data) == 0)
204                         *list = g_list_delete_link(*list, tmp);
205         }
206
207         free(locale);
208
209         return PMINFO_R_OK;
210 }
211
212 static int _appinfo_get_label(sqlite3 *db, const char *appid,
213                 const char *locale, GList **label)
214 {
215         static const char query_raw[] =
216                 "SELECT app_label, app_locale "
217                 "FROM package_app_localized_info "
218                 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
219         int ret;
220         char *query;
221         sqlite3_stmt *stmt;
222         int idx;
223         label_x *info;
224
225         query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
226         if (query == NULL) {
227                 LOGE("out of memory");
228                 return PMINFO_R_ERROR;
229         }
230
231         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
232         sqlite3_free(query);
233         if (ret != SQLITE_OK) {
234                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
235                 return PMINFO_R_ERROR;
236         }
237
238         while (sqlite3_step(stmt) == SQLITE_ROW) {
239                 info = calloc(1, sizeof(label_x));
240                 if (info == NULL) {
241                         LOGE("out of memory");
242                         sqlite3_finalize(stmt);
243                         return PMINFO_R_ERROR;
244                 }
245                 idx = 0;
246                 _save_column_str(stmt, idx++, &info->text);
247                 _save_column_str(stmt, idx++, &info->lang);
248                 *label = g_list_append(*label, info);
249         }
250
251         sqlite3_finalize(stmt);
252
253         return PMINFO_R_OK;
254 }
255
256 static void _appinfo_modify_icon(const char *appid, const char **icon)
257 {
258         char buf[PKG_VALUE_STRING_LEN_MAX];
259         const char *tmp;
260
261         if (*icon == NULL || (*icon)[0] == '/' || !strcasecmp(*icon, "(null)"))
262                 return;
263
264         tmp = *icon;
265         snprintf(buf, sizeof(buf), "%s%s.png", getIconPath(getuid()), appid);
266         *icon = strdup(buf);
267         free((char *)tmp);
268 }
269
270 static int _appinfo_get_icon(sqlite3 *db, const char *appid, const char *locale,
271                 GList **icon)
272 {
273         static const char query_raw[] =
274                 "SELECT app_icon, app_locale "
275                 "FROM package_app_localized_info "
276                 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
277         int ret;
278         char *query;
279         sqlite3_stmt *stmt;
280         int idx;
281         icon_x *info;
282
283         query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
284         if (query == NULL) {
285                 LOGE("out of memory");
286                 return PMINFO_R_ERROR;
287         }
288
289         ret = sqlite3_prepare_v2(db, query, strlen(query),
290                         &stmt, NULL);
291         sqlite3_free(query);
292         if (ret != SQLITE_OK) {
293                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
294                 return PMINFO_R_ERROR;
295         }
296
297         while (sqlite3_step(stmt) == SQLITE_ROW) {
298                 info = calloc(1, sizeof(icon_x));
299                 if (info == NULL) {
300                         LOGE("out of memory");
301                         sqlite3_finalize(stmt);
302                         return PMINFO_R_ERROR;
303                 }
304                 idx = 0;
305                 _save_column_str(stmt, idx++, &info->text);
306                 /* FIXME: this is a workaround. this must be removed later */
307                 _appinfo_modify_icon(appid, &info->text);
308                 _save_column_str(stmt, idx++, &info->lang);
309                 *icon = g_list_append(*icon, info);
310         }
311
312         sqlite3_finalize(stmt);
313
314         return PMINFO_R_OK;
315 }
316
317 static int _appinfo_get_category(sqlite3 *db, const char *appid,
318                 GList **category)
319 {
320         static const char query_raw[] =
321                 "SELECT category FROM package_app_app_category WHERE app_id=%Q";
322         int ret;
323         char *query;
324         sqlite3_stmt *stmt;
325         const char *val;
326
327         query = sqlite3_mprintf(query_raw, appid);
328         if (query == NULL) {
329                 LOGE("out of memory");
330                 return PMINFO_R_ERROR;
331         }
332
333         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
334         sqlite3_free(query);
335         if (ret != SQLITE_OK) {
336                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
337                 return PMINFO_R_ERROR;
338         }
339
340         while (sqlite3_step(stmt) == SQLITE_ROW) {
341                 val = NULL;
342                 _save_column_str(stmt, 0, &val);
343                 if (val)
344                         *category = g_list_append(*category, (gpointer)val);
345         }
346
347         sqlite3_finalize(stmt);
348
349         return PMINFO_R_OK;
350 }
351
352 static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str)
353 {
354         char *dup;
355         char *token;
356         char *ptr = NULL;
357         appcontrol_x *ac;
358
359         if (appcontrol_str == NULL)
360                 return;
361
362         dup = strdup(appcontrol_str);
363         do {
364                 ac = calloc(1, sizeof(appcontrol_x));
365                 if (ac == NULL) {
366                         _LOGE("out of memory");
367                         break;
368                 }
369                 token = strtok_r(dup, "|", &ptr);
370                 if (token && strcmp(token, "NULL"))
371                         ac->operation = strdup(token);
372                 token = strtok_r(NULL, "|", &ptr);
373                 if (token && strcmp(token, "NULL"))
374                         ac->uri = strdup(token);
375                 token = strtok_r(NULL, "|", &ptr);
376                 if (token && strcmp(token, "NULL"))
377                         ac->mime = strdup(token);
378                 *appcontrol = g_list_append(*appcontrol, ac);
379         } while ((token = strtok_r(NULL, ";", &ptr)));
380
381         free(dup);
382 }
383
384 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
385                 GList **appcontrol)
386 {
387         static const char query_raw[] =
388                 "SELECT app_control FROM package_app_app_control "
389                 "WHERE app_id=%Q";
390         int ret;
391         char *query;
392         sqlite3_stmt *stmt;
393         char *str;
394
395         query = sqlite3_mprintf(query_raw, appid);
396         if (query == NULL) {
397                 LOGE("out of memory");
398                 return PMINFO_R_ERROR;
399         }
400
401         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
402         sqlite3_free(query);
403         if (ret != SQLITE_OK) {
404                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
405                 return PMINFO_R_ERROR;
406         }
407
408         while (sqlite3_step(stmt) == SQLITE_ROW) {
409                 str = NULL;
410                 _save_column_str(stmt, 0, (const char **)&str);
411                 /* TODO: revise */
412                 __parse_appcontrol(appcontrol, str);
413                 free(str);
414         }
415
416         sqlite3_finalize(stmt);
417
418         return PMINFO_R_OK;
419 }
420
421 static int _appinfo_get_data_control(sqlite3 *db, const char *appid,
422                 GList **datacontrol)
423 {
424         static const char query_raw[] =
425                 "SELECT providerid, access, type "
426                 "FROM package_app_data_control WHERE app_id=%Q";
427         int ret;
428         char *query;
429         sqlite3_stmt *stmt;
430         int idx;
431         datacontrol_x *info;
432
433         query = sqlite3_mprintf(query_raw, appid);
434         if (query == NULL) {
435                 LOGE("out of memory");
436                 return PMINFO_R_ERROR;
437         }
438
439         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
440         sqlite3_free(query);
441         if (ret != SQLITE_OK) {
442                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
443                 return PMINFO_R_ERROR;
444         }
445
446         while (sqlite3_step(stmt) == SQLITE_ROW) {
447                 info = calloc(1, sizeof(datacontrol_x));
448                 if (info == NULL) {
449                         LOGE("out of memory");
450                         sqlite3_finalize(stmt);
451                         return PMINFO_R_ERROR;
452                 }
453                 idx = 0;
454                 _save_column_str(stmt, idx++, &info->providerid);
455                 _save_column_str(stmt, idx++, &info->access);
456                 _save_column_str(stmt, idx++, &info->type);
457                 *datacontrol = g_list_append(*datacontrol, info);
458         }
459
460         sqlite3_finalize(stmt);
461
462         return PMINFO_R_OK;
463 }
464
465 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
466                 GList **metadata)
467 {
468         static const char query_raw[] =
469                 "SELECT md_key, md_value "
470                 "FROM package_app_app_metadata WHERE app_id=%Q";
471         int ret;
472         char *query;
473         sqlite3_stmt *stmt;
474         int idx;
475         metadata_x *info;
476
477         query = sqlite3_mprintf(query_raw, appid);
478         if (query == NULL) {
479                 LOGE("out of memory");
480                 return PMINFO_R_ERROR;
481         }
482
483         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
484         sqlite3_free(query);
485         if (ret != SQLITE_OK) {
486                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
487                 return PMINFO_R_ERROR;
488         }
489
490         while (sqlite3_step(stmt) == SQLITE_ROW) {
491                 info = calloc(1, sizeof(metadata_x));
492                 if (info == NULL) {
493                         LOGE("out of memory");
494                         sqlite3_finalize(stmt);
495                         return PMINFO_R_ERROR;
496                 }
497                 idx = 0;
498                 _save_column_str(stmt, idx++, &info->key);
499                 _save_column_str(stmt, idx++, &info->value);
500                 *metadata = g_list_append(*metadata, info);
501         }
502
503         sqlite3_finalize(stmt);
504
505         return PMINFO_R_OK;
506
507 }
508
509 static GList *__get_background_category(char *value)
510 {
511         GList *category_list = NULL;
512         int convert_value = 0;
513         if (!value || strlen(value) == 0)
514                 return NULL;
515
516         convert_value = atoi(value);
517         if (convert_value < 0)
518                 return NULL;
519
520         if (convert_value & APP_BG_CATEGORY_USER_DISABLE_TRUE_VAL)
521                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_TRUE_STR));
522         else
523                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_FALSE_STR));
524
525         if (convert_value & APP_BG_CATEGORY_MEDIA_VAL)
526                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_MEDIA_STR));
527
528         if (convert_value & APP_BG_CATEGORY_DOWNLOAD_VAL)
529                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_DOWNLOAD_STR));
530
531         if (convert_value & APP_BG_CATEGORY_BGNETWORK_VAL)
532                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_BGNETWORK_STR));
533
534         if (convert_value & APP_BG_CATEGORY_LOCATION_VAL)
535                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_LOCATION_STR));
536
537         if (convert_value & APP_BG_CATEGORY_SENSOR_VAL)
538                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SENSOR_STR));
539
540         if (convert_value & APP_BG_CATEGORY_IOTCOMM_VAL)
541                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_IOTCOMM_STR));
542
543         if (convert_value & APP_BG_CATEGORY_SYSTEM_VAL)
544                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SYSTEM));
545
546         return category_list;
547
548 }
549
550 static int _appinfo_get_application(sqlite3 *db, const char *appid,
551                 const char *locale, application_x **application)
552 {
553         static const char query_raw[] =
554                 "SELECT app_id, app_component, app_exec, app_nodisplay, "
555                 "app_type, app_onboot, app_multiple, app_autorestart, "
556                 "app_taskmanage, app_enabled, app_hwacceleration, "
557                 "app_screenreader, app_mainapp, app_recentimage, "
558                 "app_launchcondition, app_indicatordisplay, app_portraitimg, "
559                 "app_landscapeimg, app_guestmodevisibility, "
560                 "app_permissiontype, app_preload, app_submode, "
561                 "app_submode_mainid, app_launch_mode, app_ui_gadget, "
562                 "app_support_disable, "
563                 "component_type, package, app_process_pool, app_installed_storage, "
564                 "app_background_category, app_package_type "
565                 "FROM package_app_info WHERE app_id='%s' AND app_disable='false' "
566                 "AND app_id NOT IN "
567                 "(SELECT app_id from package_app_disable_for_user WHERE uid='%d')";
568         int ret;
569         char query[MAX_QUERY_LEN] = { '\0' };
570         sqlite3_stmt *stmt;
571         int idx;
572         application_x *info;
573         char *bg_category_str = NULL;
574         snprintf(query, MAX_QUERY_LEN - 1, query_raw, appid, (int)getuid());
575         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
576         if (ret != SQLITE_OK) {
577                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
578                 return PMINFO_R_ERROR;
579         }
580
581         ret = sqlite3_step(stmt);
582         if (ret == SQLITE_DONE) {
583                 sqlite3_finalize(stmt);
584                 return PMINFO_R_ENOENT;
585         } else if (ret != SQLITE_ROW) {
586                 LOGE("step failed: %s", sqlite3_errmsg(db));
587                 sqlite3_finalize(stmt);
588                 return PMINFO_R_ERROR;
589         }
590
591         info = calloc(1, sizeof(application_x));
592         if (info == NULL) {
593                 LOGE("out of memory");
594                 sqlite3_finalize(stmt);
595                 return PMINFO_R_ERROR;
596         }
597         idx = 0;
598         _save_column_str(stmt, idx++, &info->appid);
599         _save_column_str(stmt, idx++, &info->component);
600         _save_column_str(stmt, idx++, &info->exec);
601         _save_column_str(stmt, idx++, &info->nodisplay);
602         _save_column_str(stmt, idx++, &info->type);
603         _save_column_str(stmt, idx++, &info->onboot);
604         _save_column_str(stmt, idx++, &info->multiple);
605         _save_column_str(stmt, idx++, &info->autorestart);
606         _save_column_str(stmt, idx++, &info->taskmanage);
607         _save_column_str(stmt, idx++, &info->enabled);
608         _save_column_str(stmt, idx++, &info->hwacceleration);
609         _save_column_str(stmt, idx++, &info->screenreader);
610         _save_column_str(stmt, idx++, &info->mainapp);
611         _save_column_str(stmt, idx++, &info->recentimage);
612         _save_column_str(stmt, idx++, &info->launchcondition);
613         _save_column_str(stmt, idx++, &info->indicatordisplay);
614         _save_column_str(stmt, idx++, &info->portraitimg);
615         _save_column_str(stmt, idx++, &info->landscapeimg);
616         _save_column_str(stmt, idx++, &info->guestmode_visibility);
617         _save_column_str(stmt, idx++, &info->permission_type);
618         _save_column_str(stmt, idx++, &info->preload);
619         _save_column_str(stmt, idx++, &info->submode);
620         _save_column_str(stmt, idx++, &info->submode_mainid);
621         _save_column_str(stmt, idx++, &info->launch_mode);
622         _save_column_str(stmt, idx++, &info->ui_gadget);
623         _save_column_str(stmt, idx++, &info->support_disable);
624         _save_column_str(stmt, idx++, &info->component_type);
625         _save_column_str(stmt, idx++, &info->package);
626         _save_column_str(stmt, idx++, &info->process_pool);
627         _save_column_str(stmt, idx++, &info->installed_storage);
628         _save_column_str(stmt, idx++, &bg_category_str);
629         _save_column_str(stmt, idx++, &info->package_type);
630
631         info->background_category = __get_background_category(bg_category_str);
632
633         if (_appinfo_get_label(db, info->appid, locale, &info->label)) {
634                 pkgmgrinfo_basic_free_application(info);
635                 sqlite3_finalize(stmt);
636                 return PMINFO_R_ERROR;
637         }
638
639         if (_appinfo_get_icon(db, info->appid, locale, &info->icon)) {
640                 pkgmgrinfo_basic_free_application(info);
641                 sqlite3_finalize(stmt);
642                 return PMINFO_R_ERROR;
643         }
644
645         if (_appinfo_get_category(db, info->appid, &info->category)) {
646                 pkgmgrinfo_basic_free_application(info);
647                 sqlite3_finalize(stmt);
648                 return PMINFO_R_ERROR;
649         }
650
651         if (_appinfo_get_app_control(db, info->appid, &info->appcontrol)) {
652                 pkgmgrinfo_basic_free_application(info);
653                 sqlite3_finalize(stmt);
654                 return PMINFO_R_ERROR;
655         }
656
657         if (_appinfo_get_data_control(db, info->appid, &info->datacontrol)) {
658                 pkgmgrinfo_basic_free_application(info);
659                 sqlite3_finalize(stmt);
660                 return PMINFO_R_ERROR;
661         }
662
663         if (_appinfo_get_metadata(db, info->appid, &info->metadata)) {
664                 pkgmgrinfo_basic_free_application(info);
665                 sqlite3_finalize(stmt);
666                 return PMINFO_R_ERROR;
667         }
668
669         *application = info;
670
671         sqlite3_finalize(stmt);
672
673         return PMINFO_R_OK;
674 }
675
676 static int _appinfo_get_appinfo(const char *appid, uid_t uid,
677                 pkgmgr_appinfo_x **appinfo)
678 {
679         int ret;
680         sqlite3 *db;
681         const char *dbpath;
682         char *locale;
683         pkgmgr_appinfo_x *info;
684
685         dbpath = getUserPkgParserDBPathUID(uid);
686         if (dbpath == NULL)
687                 return PMINFO_R_ERROR;
688
689         locale = _get_system_locale();
690         if (locale == NULL)
691                 return PMINFO_R_ERROR;
692
693         ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
694         if (ret != SQLITE_OK) {
695                 _LOGE("failed to open db: %d", ret);
696                 free(locale);
697                 return PMINFO_R_ERROR;
698         }
699
700         info = calloc(1, sizeof(pkgmgr_appinfo_x));
701         if (info == NULL) {
702                 _LOGE("out of memory");
703                 free(locale);
704                 sqlite3_close_v2(db);
705                 return PMINFO_R_ERROR;
706         }
707
708         ret = _appinfo_get_application(db, appid, locale, &info->app_info);
709         if (ret != PMINFO_R_OK) {
710                 free(info);
711                 free(locale);
712                 sqlite3_close_v2(db);
713                 return ret;
714         }
715
716         info->locale = locale;
717         info->package = strdup(info->app_info->package);
718
719         *appinfo = info;
720
721         sqlite3_close_v2(db);
722
723         return ret;
724 }
725
726 static int _appinfo_copy_appinfo(application_x **application, application_x *data)
727 {
728         application_x *app_info;
729
730         app_info = calloc(1, sizeof(application_x));
731         if (app_info == NULL) {
732                 LOGE("memory alloc failed");
733                 return PMINFO_R_ERROR;
734         }
735
736         if (data->appid != NULL)
737                 app_info->appid = strdup(data->appid);
738         if (data->exec != NULL)
739                 app_info->exec = strdup(data->exec);
740         if (data->nodisplay != NULL)
741                 app_info->nodisplay = strdup(data->nodisplay);
742         if (data->multiple != NULL)
743                 app_info->multiple = strdup(data->multiple);
744         if (data->taskmanage != NULL)
745                 app_info->taskmanage = strdup(data->taskmanage);
746         if (data->enabled != NULL)
747                 app_info->enabled = strdup(data->enabled);
748         if (data->type != NULL)
749                 app_info->type = strdup(data->type);
750         if (data->categories != NULL)
751                 app_info->categories = strdup(data->categories);
752         if (data->extraid != NULL)
753                 app_info->extraid = strdup(data->extraid);
754         if (data->hwacceleration != NULL)
755                 app_info->hwacceleration = strdup(data->hwacceleration);
756         if (data->screenreader != NULL)
757                 app_info->screenreader = strdup(data->screenreader);
758         if (data->mainapp != NULL)
759                 app_info->mainapp = strdup(data->mainapp);
760         if (data->package != NULL)
761                 app_info->package = strdup(data->package);
762         if (data->recentimage != NULL)
763                 app_info->recentimage = strdup(data->recentimage);
764         if (data->launchcondition != NULL)
765                 app_info->launchcondition = strdup(data->launchcondition);
766         if (data->indicatordisplay != NULL)
767                 app_info->indicatordisplay = strdup(data->indicatordisplay);
768         if (data->portraitimg != NULL)
769                 app_info->portraitimg = strdup(data->portraitimg);
770         if (data->landscapeimg != NULL)
771                 app_info->landscapeimg = strdup(data->landscapeimg);
772         if (data->effectimage_type != NULL)
773                 app_info->effectimage_type = strdup(data->effectimage_type);
774         if (data->guestmode_visibility != NULL)
775                 app_info->guestmode_visibility = strdup(data->guestmode_visibility);
776         if (data->component != NULL)
777                 app_info->component = strdup(data->component);
778         if (data->permission_type != NULL)
779                 app_info->permission_type = strdup(data->permission_type);
780         if (data->component_type != NULL)
781                 app_info->component_type = strdup(data->component_type);
782         if (data->preload != NULL)
783                 app_info->preload = strdup(data->preload);
784         if (data->submode != NULL)
785                 app_info->submode = strdup(data->submode);
786         if (data->submode_mainid != NULL)
787                 app_info->submode_mainid = strdup(data->submode_mainid);
788         if (data->process_pool != NULL)
789                 app_info->process_pool = strdup(data->process_pool);
790         if (data->installed_storage != NULL)
791                 app_info->installed_storage = strdup(data->installed_storage);
792         if (data->autorestart != NULL)
793                 app_info->autorestart = strdup(data->autorestart);
794         if (data->onboot != NULL)
795                 app_info->onboot = strdup(data->onboot);
796         if (data->support_disable != NULL)
797                 app_info->support_disable = strdup(data->support_disable);
798         if (data->ui_gadget != NULL)
799                 app_info->ui_gadget = strdup(data->ui_gadget);
800         if (data->launch_mode != NULL)
801                 app_info->launch_mode = strdup(data->launch_mode);
802         if (data->ambient_support != NULL)
803                 app_info->ambient_support = strdup(data->ambient_support);
804         if (data->alias_appid != NULL)
805                 app_info->alias_appid = strdup(data->alias_appid);
806         if (data->effective_appid != NULL)
807                 app_info->effective_appid = strdup(data->effective_appid);
808
809         app_info->label = g_list_copy(data->label);
810         app_info->icon = g_list_copy(data->icon);
811         app_info->image = g_list_copy(data->image);
812         app_info->category = g_list_copy(data->category);
813         app_info->metadata = g_list_copy(data->metadata);
814         app_info->permission = g_list_copy(data->permission);
815         app_info->launchconditions = g_list_copy(data->launchconditions);
816         app_info->notification = g_list_copy(data->notification);
817         app_info->datashare = g_list_copy(data->datashare);
818         app_info->datacontrol = g_list_copy(data->datacontrol);
819         app_info->background_category = g_list_copy(data->background_category);
820         app_info->appcontrol = g_list_copy(data->appcontrol);
821
822         *application = app_info;
823
824         return PMINFO_R_OK;
825 }
826
827 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
828                 pkgmgrinfo_appinfo_h *handle)
829 {
830         int ret;
831
832         if (appid == NULL || handle == NULL) {
833                 LOGE("invalid parameter");
834                 return PMINFO_R_EINVAL;
835         }
836
837         ret = _appinfo_get_appinfo(appid, uid, (pkgmgr_appinfo_x **)handle);
838         if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
839                 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
840                                 (pkgmgr_appinfo_x **)handle);
841
842         if (ret != PMINFO_R_OK)
843                 _LOGE("failed to get appinfo of %s for user %d", appid, uid);
844
845         return ret;
846 }
847
848 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
849 {
850         return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
851 }
852
853 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
854                 pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb,
855                 void *user_data)
856 {
857         int ret;
858         pkgmgr_appinfo_x *info;
859         GList *list = NULL;
860         GList *tmp;
861         char *appid;
862         int stop = 0;
863
864         ret = _appinfo_get_filtered_list(filter, uid, &list);
865         if (ret != PMINFO_R_OK)
866                 return PMINFO_R_ERROR;
867
868         for (tmp = list; tmp; tmp = tmp->next) {
869                 appid = (char *)tmp->data;
870                 if (stop == 0) {
871                         ret = _appinfo_get_appinfo(appid, uid, &info);
872                         if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
873                                 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
874                                                 &info);
875                         if (ret != PMINFO_R_OK) {
876                                 free(appid);
877                                 continue;
878                         }
879                         if (app_list_cb(info, user_data) < 0)
880                                 stop = 1;
881                         pkgmgrinfo_appinfo_destroy_appinfo(info);
882                 }
883                 free(appid);
884         }
885
886         g_list_free(list);
887
888         return PMINFO_R_OK;
889 }
890
891 API int pkgmgrinfo_appinfo_get_clone(pkgmgrinfo_appinfo_h *clone,
892                 pkgmgrinfo_appinfo_h handle)
893 {
894         pkgmgr_appinfo_x *info;
895         pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle;
896
897         if (handle == NULL)
898                 return PMINFO_R_EINVAL;
899
900         info = calloc(1, sizeof(pkgmgr_appinfo_x));
901         if (info == NULL) {
902                 LOGE("memory alloc failed");
903                 return PMINFO_R_ERROR;
904         }
905
906         if (temp->package != NULL)
907                 info->package = strdup(temp->package);
908         if (temp->locale != NULL)
909                 info->locale = strdup(temp->locale);
910
911         info->app_component = temp->app_component;
912
913         if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) {
914                 LOGE("appinfo copy failed");
915                 if (info->package)
916                         free(info->package);
917                 if (info->locale)
918                         free(info->locale);
919                 free(info);
920                 return PMINFO_R_ERROR;
921         }
922
923         *clone = info;
924
925         return PMINFO_R_OK;
926 }
927
928 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
929                 pkgmgrinfo_app_component component,
930                 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
931 {
932         int ret;
933         pkgmgrinfo_appinfo_filter_h filter;
934         char *pkgid;
935         const char *comp_str = NULL;
936
937         if (handle == NULL || app_func == NULL) {
938                 LOGE("invalid parameter");
939                 return PMINFO_R_EINVAL;
940         }
941
942         if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
943                 LOGE("invalid parameter");
944                 return PMINFO_R_EINVAL;
945         }
946
947         if (pkgmgrinfo_appinfo_filter_create(&filter))
948                 return PMINFO_R_ERROR;
949
950         if (pkgmgrinfo_appinfo_filter_add_string(filter,
951                                 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
952                 pkgmgrinfo_appinfo_filter_destroy(filter);
953                 return PMINFO_R_ERROR;
954         }
955
956         if (uid == GLOBAL_USER) {
957                 if (pkgmgrinfo_appinfo_filter_add_int(filter,
958                                         PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER, (int)getuid())) {
959                         pkgmgrinfo_appinfo_filter_destroy(filter);
960                         return PMINFO_R_ERROR;
961                 }
962         }
963
964         switch (component) {
965         case PMINFO_UI_APP:
966                 comp_str = PMINFO_APPINFO_UI_APP;
967                 break;
968         case PMINFO_SVC_APP:
969                 comp_str = PMINFO_APPINFO_SVC_APP;
970                 break;
971         default:
972                 break;
973         }
974
975         if (comp_str) {
976                 if (pkgmgrinfo_appinfo_filter_add_string(filter,
977                                         PMINFO_APPINFO_PROP_APP_COMPONENT,
978                                         comp_str)) {
979                         pkgmgrinfo_appinfo_filter_destroy(filter);
980                         return PMINFO_R_ERROR;
981                 }
982         }
983
984         ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, app_func,
985                         user_data);
986
987         pkgmgrinfo_appinfo_filter_destroy(filter);
988
989         return ret;
990 }
991
992 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
993                                                 pkgmgrinfo_app_list_cb app_func, void *user_data)
994 {
995         return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
996 }
997
998 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
999 {
1000         if (app_func == NULL) {
1001                 LOGE("invalid parameter");
1002                 return PMINFO_R_EINVAL;
1003         }
1004
1005         return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
1006                         user_data);
1007 }
1008
1009 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
1010 {
1011         return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
1012 }
1013
1014 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1015 {
1016         if (app_func == NULL) {
1017                 LOGE("invalid parameter");
1018                 return PMINFO_R_EINVAL;
1019         }
1020
1021         return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
1022                         user_data);
1023 }
1024
1025 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
1026 {
1027         return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
1028 }
1029
1030 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
1031 {
1032         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1033
1034         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1035         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1036
1037         if (info->app_info == NULL || info->app_info->appid == NULL)
1038                 return PMINFO_R_ERROR;
1039         *appid = (char *)info->app_info->appid;
1040
1041         return PMINFO_R_OK;
1042 }
1043
1044 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
1045 {
1046         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1047
1048         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1049         retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1050
1051         if (info->package == NULL)
1052                 return PMINFO_R_ERROR;
1053
1054         *pkg_name = (char *)info->package;
1055
1056         return PMINFO_R_OK;
1057 }
1058
1059 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
1060 {
1061         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1062
1063         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1064         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1065
1066         if (info->package == NULL)
1067                 return PMINFO_R_ERROR;
1068
1069         *pkgid = (char *)info->package;
1070
1071         return PMINFO_R_OK;
1072 }
1073
1074 API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h  handle, char **pkgtype)
1075 {
1076         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1077         retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1078         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1079
1080         *pkgtype = (char *)info->app_info->package_type;
1081
1082         return PMINFO_R_OK;
1083 }
1084
1085 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
1086 {
1087         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1088
1089         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1090         retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1091
1092         if (info->app_info == NULL || info->app_info->exec == NULL)
1093                 return PMINFO_R_ERROR;
1094         *exec = (char *)info->app_info->exec;
1095
1096         return PMINFO_R_OK;
1097 }
1098
1099
1100 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1101 {
1102         const char *locale;
1103         icon_x *ptr;
1104         GList *tmp;
1105         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1106
1107         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1108         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1109
1110         locale = info->locale;
1111         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1112
1113         if (info->app_info == NULL)
1114                 return PMINFO_R_ERROR;
1115
1116         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1117                 ptr = (icon_x *)tmp->data;
1118                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1119                                 !strcasecmp(ptr->text, "(null)") ||
1120                                 strcmp(ptr->lang, locale))
1121                         continue;
1122                 *icon = (char *)ptr->text;
1123                 return PMINFO_R_OK;
1124         }
1125
1126         locale = DEFAULT_LOCALE;
1127         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1128                 ptr = (icon_x *)tmp->data;
1129                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1130                                 strcmp(ptr->lang, locale))
1131                         continue;
1132                 *icon = (char *)ptr->text;
1133                 return PMINFO_R_OK;
1134         }
1135
1136         return PMINFO_R_ERROR;
1137 }
1138
1139
1140 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
1141 {
1142         const char *locale;
1143         label_x *ptr;
1144         GList *tmp;
1145         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1146
1147         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1148         retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1149
1150         locale = info->locale;
1151         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1152
1153         if (info->app_info == NULL)
1154                 return PMINFO_R_ERROR;
1155
1156         for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1157                 ptr = (label_x *)tmp->data;
1158                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1159                                 strcmp(ptr->lang, locale))
1160                         continue;
1161                 *label = (char *)ptr->text;
1162                 return PMINFO_R_OK;
1163         }
1164
1165         locale = DEFAULT_LOCALE;
1166         for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1167                 ptr = (label_x *)tmp->data;
1168                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1169                                 strcmp(ptr->lang, locale))
1170                         continue;
1171                 *label = (char *)ptr->text;
1172                 return PMINFO_R_OK;
1173         }
1174
1175         return PMINFO_R_ERROR;
1176 }
1177
1178 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1179 {
1180         char *result = NULL;
1181         char *query = NULL;
1182         sqlite3_stmt *stmt = NULL;
1183         sqlite3 *db = NULL;
1184         char *val;
1185         const char *manifest_db;
1186
1187         manifest_db = getUserPkgParserDBPathUID(uid);
1188         if (manifest_db == NULL) {
1189                 _LOGE("Failed to get manifest db path");
1190                 goto err;
1191         }
1192
1193         if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
1194                 _LOGE("DB open fail\n");
1195                 goto err;
1196         }
1197
1198         query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1199         if (query == NULL) {
1200                 _LOGE("Out of memory");
1201                 goto err;
1202         }
1203
1204         if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1205                 _LOGE("prepare_v2 fail\n");
1206                 goto err;
1207         }
1208
1209         if (sqlite3_step(stmt) == SQLITE_ROW) {
1210                 val = (char *)sqlite3_column_text(stmt, 0);
1211                 if (val != NULL)
1212                         result = strdup(val);
1213         }
1214
1215 err:
1216         sqlite3_finalize(stmt);
1217         sqlite3_free(query);
1218         sqlite3_close(db);
1219
1220         return result;
1221 }
1222
1223 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1224 {
1225         char *val;
1226
1227         retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1228
1229         val = _get_localed_label(appid, locale, uid);
1230         if (val == NULL)
1231                 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1232
1233         if (val == NULL)
1234                 return PMINFO_R_ERROR;
1235
1236         *label = val;
1237
1238         return PMINFO_R_OK;
1239 }
1240
1241 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1242 {
1243         return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
1244 }
1245
1246 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1247 {
1248         if ( strcasecmp(comp, "uiapp") == 0)
1249                 return PMINFO_UI_APP;
1250         else if ( strcasecmp(comp, "svcapp") == 0)
1251                 return PMINFO_SVC_APP;
1252         else
1253                 return -1;
1254 }
1255
1256 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1257 {
1258         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1259         int comp;
1260
1261         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1262         retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1263
1264         if (info->app_info == NULL)
1265                 return PMINFO_R_ERROR;
1266
1267         comp = __appcomponent_convert(info->app_info->component);
1268         if (comp < 0)
1269                 return PMINFO_R_ERROR;
1270
1271         *component = comp;
1272
1273         return PMINFO_R_OK;
1274 }
1275
1276 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1277 {
1278         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1279
1280         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1281         retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1282
1283         if (info->app_info == NULL || info->app_info->type == NULL)
1284                 return PMINFO_R_ERROR;
1285         *app_type = (char *)info->app_info->type;
1286
1287         return PMINFO_R_OK;
1288 }
1289
1290 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h  handle,
1291                                         int *operation_count, char ***operation)
1292 {
1293         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1294         retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1295         retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1296         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1297         *operation_count = data->operation_count;
1298         *operation = data->operation;
1299         return PMINFO_R_OK;
1300 }
1301
1302 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h  handle,
1303                                         int *uri_count, char ***uri)
1304 {
1305         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1306         retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1307         retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1308         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1309         *uri_count = data->uri_count;
1310         *uri = data->uri;
1311         return PMINFO_R_OK;
1312 }
1313
1314 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h  handle,
1315                                         int *mime_count, char ***mime)
1316 {
1317         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1318         retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1319         retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1320         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1321         *mime_count = data->mime_count;
1322         *mime = data->mime;
1323         return PMINFO_R_OK;
1324 }
1325
1326 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h  handle,
1327                                         int *subapp_count, char ***subapp)
1328 {
1329         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1330         retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1331         retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1332         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1333         *subapp_count = data->subapp_count;
1334         *subapp = data->subapp;
1335         return PMINFO_R_OK;
1336 }
1337
1338 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1339 {
1340         char *val;
1341         icon_x *ptr;
1342         GList *tmp;
1343         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1344
1345         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1346         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1347
1348         if (info->app_info == NULL)
1349                 return PMINFO_R_ERROR;
1350
1351         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1352                 ptr = (icon_x *)tmp->data;
1353                 if (ptr == NULL || ptr->section == NULL)
1354                         continue;
1355
1356                 val = (char *)ptr->section;
1357                 if (val && strcmp(val, "setting") == 0) {
1358                         *icon = (char *)ptr->text;
1359                         return PMINFO_R_OK;
1360                 }
1361         }
1362
1363         return PMINFO_R_ERROR;
1364 }
1365
1366
1367 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1368 {
1369         char *val;
1370         icon_x *ptr;
1371         GList *tmp;
1372         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1373
1374         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1375         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1376
1377         if (info->app_info == NULL)
1378                 return PMINFO_R_ERROR;
1379
1380         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1381                 ptr = (icon_x *)tmp->data;
1382                 if (ptr == NULL || ptr->section == NULL)
1383                         continue;
1384
1385                 val = (char *)ptr->section;
1386                 if (val && strcmp(val, "notification") == 0){
1387                         *icon = (char *)ptr->text;
1388                         return PMINFO_R_OK;
1389                 }
1390         }
1391
1392         return PMINFO_R_ERROR;
1393 }
1394
1395 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1396 {
1397         char *val;
1398         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1399
1400         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1401         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1402
1403         if (info->app_info == NULL || info->app_info->recentimage == NULL)
1404                 return PMINFO_R_ERROR;
1405
1406         val = (char *)info->app_info->recentimage;
1407         if (strcasecmp(val, "capture") == 0)
1408                 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1409         else if (strcasecmp(val, "icon") == 0)
1410                 *type = PMINFO_RECENTIMAGE_USE_ICON;
1411         else
1412                 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1413
1414         return PMINFO_R_OK;
1415 }
1416
1417 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1418 {
1419         char *val;
1420         image_x *ptr;
1421         GList *tmp;
1422         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1423
1424         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1425         retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1426
1427         if (info->app_info == NULL)
1428                 return PMINFO_R_ERROR;
1429
1430         for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1431                 ptr = (image_x *)tmp->data;
1432                 if (ptr == NULL || ptr->section == NULL)
1433                         continue;
1434
1435                 val = (char *)ptr->section;
1436                 if (val && strcmp(val, "preview") == 0) {
1437                         *preview_img = (char *)ptr->text;
1438                         return PMINFO_R_OK;
1439                 }
1440         }
1441
1442         return PMINFO_R_ERROR;
1443 }
1444
1445 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1446 {
1447         const char *val;
1448         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1449
1450         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1451         retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1452
1453         val = info->app_info->permission_type;
1454         if (val == NULL)
1455                 return PMINFO_R_ERROR;
1456
1457         if (strcmp(val, "signature") == 0)
1458                 *permission = PMINFO_PERMISSION_SIGNATURE;
1459         else if (strcmp(val, "privilege") == 0)
1460                 *permission = PMINFO_PERMISSION_PRIVILEGE;
1461         else
1462                 *permission = PMINFO_PERMISSION_NORMAL;
1463
1464         return PMINFO_R_OK;
1465 }
1466
1467 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1468 {
1469         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1470
1471         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1472         retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1473
1474         if (info->app_info == NULL || info->app_info->component_type == NULL)
1475                 return PMINFO_R_ERROR;
1476
1477         *component_type = (char *)info->app_info->component_type;
1478
1479         return PMINFO_R_OK;
1480 }
1481
1482 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1483 {
1484         char *val;
1485         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1486
1487         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1488         retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1489
1490         if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1491                 return PMINFO_R_ERROR;
1492
1493         val = (char *)info->app_info->hwacceleration;
1494         if (strcasecmp(val, "not-use-GL") == 0)
1495                 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
1496         else if (strcasecmp(val, "use-GL") == 0)
1497                 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
1498         else
1499                 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
1500
1501         return PMINFO_R_OK;
1502 }
1503
1504 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1505 {
1506         char *val;
1507         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1508
1509         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1510         retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1511
1512         if (info->app_info == NULL || info->app_info->screenreader == NULL)
1513                 return PMINFO_R_ERROR;
1514
1515         val = (char *)info->app_info->screenreader;
1516         if (strcasecmp(val, "screenreader-off") == 0)
1517                 *screenreader = PMINFO_SCREENREADER_OFF;
1518         else if (strcasecmp(val, "screenreader-on") == 0)
1519                 *screenreader = PMINFO_SCREENREADER_ON;
1520         else
1521                 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1522
1523         return PMINFO_R_OK;
1524 }
1525
1526 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1527 {
1528         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1529
1530         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1531         retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1532         retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1533
1534         if (info->app_info == NULL || info->app_info->portraitimg ||
1535                         info->app_info->landscapeimg == NULL)
1536                 return PMINFO_R_ERROR;
1537
1538         *portrait_img = (char *)info->app_info->portraitimg;
1539         *landscape_img = (char *)info->app_info->landscapeimg;
1540
1541         return PMINFO_R_OK;
1542 }
1543
1544 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
1545 {
1546         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1547
1548         if (handle == NULL || effectimage_type == NULL) {
1549                 LOGE("invalid parameter");
1550                 return PMINFO_R_EINVAL;
1551         }
1552
1553         if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
1554                 return PMINFO_R_ERROR;
1555
1556         *effectimage_type = (char *)info->app_info->effectimage_type;
1557
1558         return PMINFO_R_OK;
1559 }
1560
1561 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h  handle, char **submode_mainid)
1562 {
1563         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1564
1565         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1566         retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1567
1568         if (info->app_info == NULL || info->app_info->submode_mainid == NULL)
1569                 return PMINFO_R_ERROR;
1570
1571         *submode_mainid = (char *)info->app_info->submode_mainid;
1572
1573         return PMINFO_R_OK;
1574 }
1575
1576 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
1577 {
1578         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1579         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1580
1581         if (info->app_info && info->app_info->installed_storage){
1582                  if (strcmp(info->app_info->installed_storage,"installed_internal") == 0)
1583                         *storage = PMINFO_INTERNAL_STORAGE;
1584                  else if (strcmp(info->app_info->installed_storage,"installed_external") == 0)
1585                          *storage = PMINFO_EXTERNAL_STORAGE;
1586                  else
1587                          return PMINFO_R_ERROR;
1588         }else
1589                 return PMINFO_R_ERROR;
1590
1591         return PMINFO_R_OK;
1592 }
1593
1594 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
1595 {
1596         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1597
1598         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1599         retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1600
1601         if (info->app_info->launch_mode == NULL)
1602                 return PMINFO_R_ERROR;
1603
1604         *mode = (char *)(info->app_info->launch_mode);
1605
1606         return PMINFO_R_OK;
1607 }
1608
1609 API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
1610 {
1611         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1612
1613         if (handle == NULL || alias_appid == NULL) {
1614                 LOGE("invalid parameter");
1615                 return PMINFO_R_EINVAL;
1616         }
1617
1618         if (info->app_info == NULL || info->app_info->alias_appid == NULL)
1619                 return PMINFO_R_ERROR;
1620
1621         *alias_appid = (char *)info->app_info->alias_appid;
1622
1623         return PMINFO_R_OK;
1624 }
1625
1626 API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
1627 {
1628         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1629
1630         if (handle == NULL || effective_appid == NULL) {
1631                 LOGE("invalid parameter");
1632                 return PMINFO_R_EINVAL;
1633         }
1634
1635         if (info->app_info == NULL || info->app_info->effective_appid == NULL)
1636                 return PMINFO_R_ERROR;
1637
1638         *effective_appid = (char *)info->app_info->effective_appid;
1639
1640         return PMINFO_R_OK;
1641 }
1642
1643 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
1644 {
1645         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1646         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1647         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1648         retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1649
1650         int ret = PMINFO_R_OK;
1651         char *query = NULL;
1652         sqlite3_stmt *stmt = NULL;
1653
1654         /*open db*/
1655         ret = __open_manifest_db(uid, true);
1656         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1657
1658         /*Start constructing query*/
1659         query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
1660
1661         /*prepare query*/
1662         ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1663         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1664
1665         /*step query*/
1666         ret = sqlite3_step(stmt);
1667         tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1668
1669         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1670         *access = strdup((char *)sqlite3_column_text(stmt, 2));
1671
1672         ret = PMINFO_R_OK;
1673
1674 catch:
1675         sqlite3_free(query);
1676         sqlite3_finalize(stmt);
1677         __close_manifest_db();
1678         return ret;
1679 }
1680
1681 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
1682 {
1683         return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
1684 }
1685
1686 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
1687 {
1688         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1689         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1690
1691         int ret = PMINFO_R_OK;
1692         char *query = NULL;
1693         sqlite3_stmt *stmt = NULL;
1694
1695         /*open db*/
1696         ret = __open_manifest_db(uid, true);
1697         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1698
1699         /*Start constructing query*/
1700         query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
1701
1702         /*prepare query*/
1703         ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1704         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1705
1706         /*step query*/
1707         ret = sqlite3_step(stmt);
1708         tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1709
1710         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1711
1712         ret = PMINFO_R_OK;
1713
1714 catch:
1715         sqlite3_free(query);
1716         sqlite3_finalize(stmt);
1717         __close_manifest_db();
1718         return ret;
1719 }
1720
1721 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1722 {
1723         return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
1724 }
1725
1726 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
1727                         pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
1728 {
1729         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1730         retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1731         int ret = -1;
1732         permission_x *ptr;
1733         GList *tmp;
1734         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1735
1736         if (info->app_info == NULL)
1737                 return PMINFO_R_ERROR;
1738
1739         for (tmp = info->app_info->permission; tmp; tmp = tmp->next) {
1740                 ptr = (permission_x *)tmp->data;
1741                 if (ptr == NULL)
1742                         continue;
1743                 if (ptr->value) {
1744                         ret = permission_func(ptr->value, user_data);
1745                         if (ret < 0)
1746                                 break;
1747                 }
1748         }
1749         return PMINFO_R_OK;
1750 }
1751
1752 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
1753                         pkgmgrinfo_app_category_list_cb category_func, void *user_data)
1754 {
1755         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1756         retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1757         int ret = -1;
1758         const char *category;
1759         GList *tmp;
1760         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1761
1762         if (info->app_info == NULL)
1763                 return PMINFO_R_ERROR;
1764
1765         for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
1766                 category = (const char *)tmp->data;
1767                 if (category) {
1768                         ret = category_func(category, user_data);
1769                         if (ret < 0)
1770                                 break;
1771                 }
1772         }
1773         return PMINFO_R_OK;
1774 }
1775
1776 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
1777                         pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
1778 {
1779         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1780         retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1781         int ret = -1;
1782         metadata_x *ptr;
1783         GList *tmp;
1784         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1785
1786         if (info->app_info == NULL)
1787                 return PMINFO_R_ERROR;
1788
1789         for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
1790                 ptr = (metadata_x *)tmp->data;
1791                 if (ptr == NULL)
1792                         continue;
1793                 if (ptr->key) {
1794                         ret = metadata_func(ptr->key, ptr->value, user_data);
1795                         if (ret < 0)
1796                                 break;
1797                 }
1798         }
1799         return PMINFO_R_OK;
1800 }
1801
1802 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
1803                         pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1804 {
1805         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1806         retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1807         int ret;
1808         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1809         appcontrol_x *appcontrol;
1810         GList *tmp;
1811
1812         if (info->app_info == NULL)
1813                 return PMINFO_R_ERROR;
1814
1815         for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
1816                 appcontrol = (appcontrol_x *)tmp->data;
1817                 if (appcontrol == NULL)
1818                         continue;
1819                 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1820                 if (ret < 0)
1821                         break;
1822         }
1823
1824         return PMINFO_R_OK;
1825 }
1826
1827 API int pkgmgrinfo_appinfo_foreach_background_category(
1828                 pkgmgrinfo_appinfo_h handle,
1829                 pkgmgrinfo_app_background_category_list_cb category_func,
1830                 void *user_data)
1831 {
1832         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1833         GList *tmp;
1834         char *category;
1835
1836         if (handle == NULL || category_func == NULL || info->app_info == NULL) {
1837                 LOGE("invalid parameter");
1838                 return PMINFO_R_EINVAL;
1839         }
1840
1841         for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
1842                 category = (char *)tmp->data;
1843                 if (category == NULL)
1844                         continue;
1845
1846                 if (category_func(category, user_data) < 0)
1847                         break;
1848         }
1849
1850         return PMINFO_R_OK;
1851 }
1852
1853 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
1854 {
1855         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1856         retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1857         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1858
1859         if (info->app_info == NULL || info->app_info->nodisplay == NULL)
1860                 return PMINFO_R_ERROR;
1861
1862         *nodisplay = _get_bool_value(info->app_info->nodisplay);
1863
1864         return PMINFO_R_OK;
1865 }
1866
1867 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
1868 {
1869         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1870         retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1871         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1872
1873         if (info->app_info == NULL || info->app_info->multiple == NULL)
1874                 return PMINFO_R_ERROR;
1875
1876         *multiple = _get_bool_value(info->app_info->multiple);
1877
1878         return PMINFO_R_OK;
1879 }
1880
1881 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
1882 {
1883         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1884         retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1885         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1886
1887         if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
1888                 return PMINFO_R_ERROR;
1889
1890         *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
1891
1892         return PMINFO_R_OK;
1893 }
1894
1895 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h  handle, bool *taskmanage)
1896 {
1897         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1898         retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1899         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1900
1901         if (info->app_info == NULL || info->app_info->taskmanage == NULL)
1902                 return PMINFO_R_ERROR;
1903
1904         *taskmanage = _get_bool_value(info->app_info->taskmanage);
1905
1906         return PMINFO_R_OK;
1907 }
1908
1909 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h  handle, bool *enabled)
1910 {
1911         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1912         retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1913         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1914
1915         if (info->app_info == NULL || info->app_info->enabled == NULL)
1916                 return PMINFO_R_ERROR;
1917
1918         *enabled = _get_bool_value(info->app_info->enabled);
1919
1920         return PMINFO_R_OK;
1921 }
1922
1923 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h  handle, bool *onboot)
1924 {
1925         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1926         retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1927         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1928
1929         if (info->app_info == NULL || info->app_info->onboot == NULL)
1930                 return PMINFO_R_ERROR;
1931
1932         *onboot = _get_bool_value(info->app_info->onboot);
1933
1934         return PMINFO_R_OK;
1935 }
1936
1937 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h  handle, bool *autorestart)
1938 {
1939         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1940         retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1941         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1942
1943         if (info->app_info == NULL || info->app_info->autorestart == NULL)
1944                 return PMINFO_R_ERROR;
1945
1946         *autorestart = _get_bool_value(info->app_info->autorestart);
1947
1948         return PMINFO_R_OK;
1949 }
1950
1951 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h  handle, bool *mainapp)
1952 {
1953         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1954         retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1955         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1956
1957         if (info->app_info == NULL || info->app_info->mainapp == NULL)
1958                 return PMINFO_R_ERROR;
1959
1960         *mainapp = _get_bool_value(info->app_info->mainapp);
1961
1962         return PMINFO_R_OK;
1963 }
1964
1965 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
1966 {
1967         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1968         retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1969         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1970
1971         if (info->app_info == NULL || info->app_info->preload == NULL)
1972                 return PMINFO_R_ERROR;
1973
1974         *preload = _get_bool_value(info->app_info->preload);
1975
1976         return PMINFO_R_OK;
1977 }
1978
1979 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
1980 {
1981         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1982         retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1983         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1984
1985         if (info->app_info == NULL || info->app_info->submode == NULL)
1986                 return PMINFO_R_ERROR;
1987
1988         *submode = _get_bool_value(info->app_info->submode);
1989
1990         return PMINFO_R_OK;
1991 }
1992
1993 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
1994 {
1995         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1996
1997         if (handle == NULL || process_pool == NULL) {
1998                 LOGE("invalid parameter");
1999                 return PMINFO_R_EINVAL;
2000         }
2001
2002         if (info->app_info == NULL)
2003                 return PMINFO_R_ERROR;
2004
2005         *process_pool = _get_bool_value(info->app_info->process_pool);
2006
2007         return PMINFO_R_OK;
2008 }
2009
2010 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
2011 {
2012         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2013         retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
2014         retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
2015
2016         const char *val;
2017         GList *tmp;
2018         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2019
2020         if (info->app_info == NULL)
2021                 return PMINFO_R_ERROR;
2022
2023         *exist = 0;
2024         for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2025                 val = (const char *)tmp->data;
2026                 if (val == NULL)
2027                         continue;
2028                 if (strcasecmp(val, category) == 0) {
2029                         *exist = 1;
2030                         break;
2031                 }
2032         }
2033
2034         return PMINFO_R_OK;
2035 }
2036
2037 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
2038                 bool *ui_gadget)
2039 {
2040         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2041
2042         if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
2043                 _LOGE("invalid parameter");
2044                 return PMINFO_R_EINVAL;
2045         }
2046
2047         *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
2048
2049         return PMINFO_R_OK;
2050 }
2051
2052 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
2053                 bool *support_disable)
2054 {
2055         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2056
2057         if (info == NULL || info->app_info == NULL || support_disable == NULL) {
2058                 _LOGE("invalid parameter");
2059                 return PMINFO_R_EINVAL;
2060         }
2061
2062         *support_disable = _get_bool_value(info->app_info->support_disable);
2063
2064         return PMINFO_R_OK;
2065 }
2066
2067 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
2068 {
2069         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2070         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2071         __cleanup_appinfo(info);
2072         return PMINFO_R_OK;
2073 }
2074
2075 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
2076 {
2077         return (pkgmgrinfo_pkginfo_filter_create(handle));
2078 }
2079
2080 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
2081 {
2082         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2083 }
2084
2085 static gint __compare_func(gconstpointer data1, gconstpointer data2)
2086 {
2087         pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
2088         pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
2089         if (node1->prop == node2->prop)
2090                 return 0;
2091         else if (node1->prop > node2->prop)
2092                 return 1;
2093         else
2094                 return -1;
2095 }
2096
2097 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
2098                                 const char *property, const int value)
2099 {
2100         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2101         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2102         char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
2103         char *val = NULL;
2104         GSList *link = NULL;
2105         int prop = -1;
2106         prop = _pminfo_appinfo_convert_to_prop_int(property);
2107         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
2108                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
2109                 _LOGE("Invalid Integer Property\n");
2110                 return PMINFO_R_EINVAL;
2111         }
2112         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2113         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2114         if (node == NULL) {
2115                 _LOGE("Out of Memory!!!\n");
2116                 return PMINFO_R_ERROR;
2117         }
2118         snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
2119         val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
2120         if (val == NULL) {
2121                 _LOGE("Out of Memory\n");
2122                 free(node);
2123                 node = NULL;
2124                 return PMINFO_R_ERROR;
2125         }
2126         node->prop = prop;
2127         node->value = val;
2128         /*If API is called multiple times for same property, we should override the previous values.
2129         Last value set will be used for filtering.*/
2130         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2131         if (link)
2132                 filter->list = g_slist_delete_link(filter->list, link);
2133         filter->list = g_slist_append(filter->list, (gpointer)node);
2134         return PMINFO_R_OK;
2135
2136 }
2137
2138 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
2139                                 const char *property, const bool value)
2140 {
2141         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2142         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2143         char *val = NULL;
2144         GSList *link = NULL;
2145         int prop = -1;
2146         prop = _pminfo_appinfo_convert_to_prop_bool(property);
2147         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
2148                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
2149                 _LOGE("Invalid Boolean Property\n");
2150                 return PMINFO_R_EINVAL;
2151         }
2152         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2153         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2154         if (node == NULL) {
2155                 _LOGE("Out of Memory!!!\n");
2156                 return PMINFO_R_ERROR;
2157         }
2158         if (value)
2159                 val = strndup("('true','True')", 15);
2160         else
2161                 val = strndup("('false','False')", 17);
2162         if (val == NULL) {
2163                 _LOGE("Out of Memory\n");
2164                 free(node);
2165                 node = NULL;
2166                 return PMINFO_R_ERROR;
2167         }
2168         node->prop = prop;
2169         node->value = val;
2170         /*If API is called multiple times for same property, we should override the previous values.
2171         Last value set will be used for filtering.*/
2172         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2173         if (link)
2174                 filter->list = g_slist_delete_link(filter->list, link);
2175         filter->list = g_slist_append(filter->list, (gpointer)node);
2176         return PMINFO_R_OK;
2177
2178 }
2179
2180 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
2181                                 const char *property, const char *value)
2182 {
2183         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2184         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2185         retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2186         char *val = NULL;
2187         pkgmgrinfo_node_x *ptr = NULL;
2188         char prev[PKG_STRING_LEN_MAX] = {'\0'};
2189         char temp[PKG_STRING_LEN_MAX] = {'\0'};
2190         GSList *link = NULL;
2191         int prop = -1;
2192         prop = _pminfo_appinfo_convert_to_prop_str(property);
2193         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
2194                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
2195                 _LOGE("Invalid String Property\n");
2196                 return PMINFO_R_EINVAL;
2197         }
2198         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2199         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2200         if (node == NULL) {
2201                 _LOGE("Out of Memory!!!\n");
2202                 return PMINFO_R_ERROR;
2203         }
2204         node->prop = prop;
2205         switch (prop) {
2206         case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
2207                 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
2208                         val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
2209                 else
2210                         val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
2211                 node->value = val;
2212                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2213                 if (link)
2214                         filter->list = g_slist_delete_link(filter->list, link);
2215                 filter->list = g_slist_append(filter->list, (gpointer)node);
2216                 break;
2217         case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
2218         case E_PMINFO_APPINFO_PROP_APP_OPERATION:
2219         case E_PMINFO_APPINFO_PROP_APP_URI:
2220         case E_PMINFO_APPINFO_PROP_APP_MIME:
2221                 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
2222                 if (val == NULL) {
2223                         _LOGE("Out of Memory\n");
2224                         free(node);
2225                         node = NULL;
2226                         return PMINFO_R_ERROR;
2227                 }
2228                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2229                 if (link) {
2230                         ptr = (pkgmgrinfo_node_x *)link->data;
2231                         strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
2232                         _LOGE("Previous value is %s\n", prev);
2233                         filter->list = g_slist_delete_link(filter->list, link);
2234                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
2235                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
2236                         _LOGE("New value is %s\n", val);
2237                         node->value = val;
2238                         filter->list = g_slist_append(filter->list, (gpointer)node);
2239                         memset(temp, '\0', PKG_STRING_LEN_MAX);
2240                 } else {
2241                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
2242                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
2243                         _LOGE("First value is %s\n", val);
2244                         node->value = val;
2245                         filter->list = g_slist_append(filter->list, (gpointer)node);
2246                         memset(temp, '\0', PKG_STRING_LEN_MAX);
2247                 }
2248                 break;
2249         default:
2250                 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
2251                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2252                 if (link)
2253                         filter->list = g_slist_delete_link(filter->list, link);
2254                 filter->list = g_slist_append(filter->list, (gpointer)node);
2255                 break;
2256         }
2257         return PMINFO_R_OK;
2258 }
2259
2260 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
2261 {
2262         int ret;
2263         GList *list = NULL;
2264
2265         if (handle == NULL || count == NULL) {
2266                 _LOGE("invalid parameter");
2267                 return PMINFO_R_EINVAL;
2268         }
2269
2270         ret = _appinfo_get_filtered_list(handle, uid, &list);
2271         if (ret != PMINFO_R_OK)
2272                 return PMINFO_R_ERROR;
2273
2274         *count = g_list_length(list);
2275
2276         g_list_free_full(list, free);
2277
2278         return PMINFO_R_OK;
2279 }
2280
2281 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
2282 {
2283         return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
2284 }
2285
2286 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
2287                 pkgmgrinfo_appinfo_filter_h handle,
2288                 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2289 {
2290         if (handle == NULL || app_cb == NULL) {
2291                 LOGE("invalid parameter");
2292                 return PMINFO_R_EINVAL;
2293         }
2294
2295         return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2296                         user_data);
2297 }
2298
2299 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
2300                                 pkgmgrinfo_app_list_cb app_cb, void * user_data)
2301 {
2302         return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
2303 }
2304
2305 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
2306 {
2307         return (pkgmgrinfo_pkginfo_filter_create(handle));
2308 }
2309
2310 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
2311 {
2312         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2313 }
2314
2315 API int pkgmgrinfo_appinfo_metadata_filter_add(
2316                 pkgmgrinfo_appinfo_metadata_filter_h handle,
2317                 const char *key, const char *value)
2318 {
2319         int ret;
2320
2321         ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2322                         PMINFO_APPINFO_PROP_APP_METADATA_KEY, key);
2323         if (ret != PMINFO_R_OK)
2324                 return ret;
2325
2326         /* value can be NULL.
2327          * In that case all apps with specified key should be displayed
2328          */
2329         if (value) {
2330                 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2331                                 PMINFO_APPINFO_PROP_APP_METADATA_VALUE, value);
2332                 if (ret != PMINFO_R_OK)
2333                         return ret;
2334         }
2335
2336         return PMINFO_R_OK;
2337 }
2338
2339 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2340                 pkgmgrinfo_appinfo_metadata_filter_h handle,
2341                 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2342 {
2343         if (handle == NULL || app_cb == NULL) {
2344                 LOGE("invalid parameter");
2345                 return PMINFO_R_EINVAL;
2346         }
2347
2348         return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2349                         user_data);
2350 }
2351
2352 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
2353                 pkgmgrinfo_appinfo_metadata_filter_h handle,
2354                 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2355 {
2356         return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
2357                         user_data, GLOBAL_USER);
2358 }
2359
2360 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2361 {
2362         const char *val;
2363         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2364
2365         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2366         retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2367
2368         val = info->app_info->guestmode_visibility;
2369         *status = _get_bool_value(val);
2370         return PMINFO_R_OK;
2371 }