Add missed DB column and APIs for process pool, TEP and
[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 int _appinfo_get_icon(sqlite3 *db, const char *appid, const char *locale,
257                 GList **icon)
258 {
259         static const char query_raw[] =
260                 "SELECT app_icon, app_locale "
261                 "FROM package_app_localized_info "
262                 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
263         int ret;
264         char *query;
265         sqlite3_stmt *stmt;
266         int idx;
267         icon_x *info;
268
269         query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
270         if (query == NULL) {
271                 LOGE("out of memory");
272                 return PMINFO_R_ERROR;
273         }
274
275         ret = sqlite3_prepare_v2(db, query, strlen(query),
276                         &stmt, NULL);
277         sqlite3_free(query);
278         if (ret != SQLITE_OK) {
279                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
280                 return PMINFO_R_ERROR;
281         }
282
283         while (sqlite3_step(stmt) == SQLITE_ROW) {
284                 info = calloc(1, sizeof(icon_x));
285                 if (info == NULL) {
286                         LOGE("out of memory");
287                         sqlite3_finalize(stmt);
288                         return PMINFO_R_ERROR;
289                 }
290                 idx = 0;
291                 _save_column_str(stmt, idx++, &info->text);
292                 _save_column_str(stmt, idx++, &info->lang);
293                 *icon = g_list_append(*icon, info);
294         }
295
296         sqlite3_finalize(stmt);
297
298         return PMINFO_R_OK;
299 }
300
301 static int _appinfo_get_category(sqlite3 *db, const char *appid,
302                 GList **category)
303 {
304         static const char query_raw[] =
305                 "SELECT category FROM package_app_app_category WHERE app_id=%Q";
306         int ret;
307         char *query;
308         sqlite3_stmt *stmt;
309         const char *val;
310
311         query = sqlite3_mprintf(query_raw, appid);
312         if (query == NULL) {
313                 LOGE("out of memory");
314                 return PMINFO_R_ERROR;
315         }
316
317         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
318         sqlite3_free(query);
319         if (ret != SQLITE_OK) {
320                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
321                 return PMINFO_R_ERROR;
322         }
323
324         while (sqlite3_step(stmt) == SQLITE_ROW) {
325                 val = NULL;
326                 _save_column_str(stmt, 0, &val);
327                 if (val)
328                         *category = g_list_append(*category, (gpointer)val);
329         }
330
331         sqlite3_finalize(stmt);
332
333         return PMINFO_R_OK;
334 }
335
336 static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str)
337 {
338         char *dup;
339         char *token;
340         char *ptr = NULL;
341         appcontrol_x *ac;
342
343         if (appcontrol_str == NULL)
344                 return;
345
346         dup = strdup(appcontrol_str);
347         do {
348                 ac = calloc(1, sizeof(appcontrol_x));
349                 if (ac == NULL) {
350                         _LOGE("out of memory");
351                         break;
352                 }
353                 token = strtok_r(dup, "|", &ptr);
354                 if (token && strcmp(token, "NULL"))
355                         ac->operation = strdup(token);
356                 token = strtok_r(NULL, "|", &ptr);
357                 if (token && strcmp(token, "NULL"))
358                         ac->uri = strdup(token);
359                 token = strtok_r(NULL, "|", &ptr);
360                 if (token && strcmp(token, "NULL"))
361                         ac->mime = strdup(token);
362                 *appcontrol = g_list_append(*appcontrol, ac);
363         } while ((token = strtok_r(NULL, ";", &ptr)));
364
365         free(dup);
366 }
367
368 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
369                 GList **appcontrol)
370 {
371         static const char query_raw[] =
372                 "SELECT app_control FROM package_app_app_control "
373                 "WHERE app_id=%Q";
374         int ret;
375         char *query;
376         sqlite3_stmt *stmt;
377         char *str;
378
379         query = sqlite3_mprintf(query_raw, appid);
380         if (query == NULL) {
381                 LOGE("out of memory");
382                 return PMINFO_R_ERROR;
383         }
384
385         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
386         sqlite3_free(query);
387         if (ret != SQLITE_OK) {
388                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
389                 return PMINFO_R_ERROR;
390         }
391
392         while (sqlite3_step(stmt) == SQLITE_ROW) {
393                 str = NULL;
394                 _save_column_str(stmt, 0, (const char **)&str);
395                 /* TODO: revise */
396                 __parse_appcontrol(appcontrol, str);
397                 free(str);
398         }
399
400         sqlite3_finalize(stmt);
401
402         return PMINFO_R_OK;
403 }
404
405 static int _appinfo_get_data_control(sqlite3 *db, const char *appid,
406                 GList **datacontrol)
407 {
408         static const char query_raw[] =
409                 "SELECT providerid, access, type "
410                 "FROM package_app_data_control WHERE app_id=%Q";
411         int ret;
412         char *query;
413         sqlite3_stmt *stmt;
414         int idx;
415         datacontrol_x *info;
416
417         query = sqlite3_mprintf(query_raw, appid);
418         if (query == NULL) {
419                 LOGE("out of memory");
420                 return PMINFO_R_ERROR;
421         }
422
423         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
424         sqlite3_free(query);
425         if (ret != SQLITE_OK) {
426                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
427                 return PMINFO_R_ERROR;
428         }
429
430         while (sqlite3_step(stmt) == SQLITE_ROW) {
431                 info = calloc(1, sizeof(datacontrol_x));
432                 if (info == NULL) {
433                         LOGE("out of memory");
434                         sqlite3_finalize(stmt);
435                         return PMINFO_R_ERROR;
436                 }
437                 idx = 0;
438                 _save_column_str(stmt, idx++, &info->providerid);
439                 _save_column_str(stmt, idx++, &info->access);
440                 _save_column_str(stmt, idx++, &info->type);
441                 *datacontrol = g_list_append(*datacontrol, info);
442         }
443
444         sqlite3_finalize(stmt);
445
446         return PMINFO_R_OK;
447 }
448
449 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
450                 GList **metadata)
451 {
452         static const char query_raw[] =
453                 "SELECT md_key, md_value "
454                 "FROM package_app_app_metadata WHERE app_id=%Q";
455         int ret;
456         char *query;
457         sqlite3_stmt *stmt;
458         int idx;
459         metadata_x *info;
460
461         query = sqlite3_mprintf(query_raw, appid);
462         if (query == NULL) {
463                 LOGE("out of memory");
464                 return PMINFO_R_ERROR;
465         }
466
467         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
468         sqlite3_free(query);
469         if (ret != SQLITE_OK) {
470                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
471                 return PMINFO_R_ERROR;
472         }
473
474         while (sqlite3_step(stmt) == SQLITE_ROW) {
475                 info = calloc(1, sizeof(metadata_x));
476                 if (info == NULL) {
477                         LOGE("out of memory");
478                         sqlite3_finalize(stmt);
479                         return PMINFO_R_ERROR;
480                 }
481                 idx = 0;
482                 _save_column_str(stmt, idx++, &info->key);
483                 _save_column_str(stmt, idx++, &info->value);
484                 *metadata = g_list_append(*metadata, info);
485         }
486
487         sqlite3_finalize(stmt);
488
489         return PMINFO_R_OK;
490
491 }
492
493 static int _appinfo_get_application(sqlite3 *db, const char *appid,
494                 const char *locale, application_x **application)
495 {
496         static const char query_raw[] =
497                 "SELECT app_id, app_component, app_exec, app_nodisplay, "
498                 "app_type, app_onboot, app_multiple, app_autorestart, "
499                 "app_taskmanage, app_enabled, app_hwacceleration, "
500                 "app_screenreader, app_mainapp, app_recentimage, "
501                 "app_launchcondition, app_indicatordisplay, app_portraitimg, "
502                 "app_landscapeimg, app_guestmodevisibility, "
503                 "app_permissiontype, app_preload, app_submode, "
504                 "app_submode_mainid, app_launch_mode, app_ui_gadget, "
505                 "app_support_disable, "
506                 "component_type, package, app_process_pool, app_installed_storage "
507                 "FROM package_app_info WHERE app_id=%Q";
508         int ret;
509         char *query;
510         sqlite3_stmt *stmt;
511         int idx;
512         application_x *info;
513
514         query = sqlite3_mprintf(query_raw, appid);
515         if (query == NULL) {
516                 LOGE("out of memory");
517                 return PMINFO_R_ERROR;
518         }
519
520         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
521         sqlite3_free(query);
522         if (ret != SQLITE_OK) {
523                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
524                 return PMINFO_R_ERROR;
525         }
526
527         ret = sqlite3_step(stmt);
528         if (ret == SQLITE_DONE) {
529                 sqlite3_finalize(stmt);
530                 return PMINFO_R_ENOENT;
531         } else if (ret != SQLITE_ROW) {
532                 LOGE("step failed: %s", sqlite3_errmsg(db));
533                 sqlite3_finalize(stmt);
534                 return PMINFO_R_ERROR;
535         }
536
537         info = calloc(1, sizeof(application_x));
538         if (info == NULL) {
539                 LOGE("out of memory");
540                 sqlite3_finalize(stmt);
541                 return PMINFO_R_ERROR;
542         }
543         idx = 0;
544         _save_column_str(stmt, idx++, &info->appid);
545         _save_column_str(stmt, idx++, &info->component);
546         _save_column_str(stmt, idx++, &info->exec);
547         _save_column_str(stmt, idx++, &info->nodisplay);
548         _save_column_str(stmt, idx++, &info->type);
549         _save_column_str(stmt, idx++, &info->onboot);
550         _save_column_str(stmt, idx++, &info->multiple);
551         _save_column_str(stmt, idx++, &info->autorestart);
552         _save_column_str(stmt, idx++, &info->taskmanage);
553         _save_column_str(stmt, idx++, &info->enabled);
554         _save_column_str(stmt, idx++, &info->hwacceleration);
555         _save_column_str(stmt, idx++, &info->screenreader);
556         _save_column_str(stmt, idx++, &info->mainapp);
557         _save_column_str(stmt, idx++, &info->recentimage);
558         _save_column_str(stmt, idx++, &info->launchcondition);
559         _save_column_str(stmt, idx++, &info->indicatordisplay);
560         _save_column_str(stmt, idx++, &info->portraitimg);
561         _save_column_str(stmt, idx++, &info->landscapeimg);
562         _save_column_str(stmt, idx++, &info->guestmode_visibility);
563         _save_column_str(stmt, idx++, &info->permission_type);
564         _save_column_str(stmt, idx++, &info->preload);
565         _save_column_str(stmt, idx++, &info->submode);
566         _save_column_str(stmt, idx++, &info->submode_mainid);
567         _save_column_str(stmt, idx++, &info->launch_mode);
568         _save_column_str(stmt, idx++, &info->ui_gadget);
569         _save_column_str(stmt, idx++, &info->support_disable);
570         _save_column_str(stmt, idx++, &info->component_type);
571         _save_column_str(stmt, idx++, &info->package);
572         _save_column_str(stmt, idx++, &info->process_pool);
573         _save_column_str(stmt, idx++, &info->installed_storage);
574
575         if (_appinfo_get_label(db, info->appid, locale, &info->label)) {
576                 pkgmgrinfo_basic_free_application(info);
577                 sqlite3_finalize(stmt);
578                 return PMINFO_R_ERROR;
579         }
580
581         if (_appinfo_get_icon(db, info->appid, locale, &info->icon)) {
582                 pkgmgrinfo_basic_free_application(info);
583                 sqlite3_finalize(stmt);
584                 return PMINFO_R_ERROR;
585         }
586
587         if (_appinfo_get_category(db, info->appid, &info->category)) {
588                 pkgmgrinfo_basic_free_application(info);
589                 sqlite3_finalize(stmt);
590                 return PMINFO_R_ERROR;
591         }
592
593         if (_appinfo_get_app_control(db, info->appid, &info->appcontrol)) {
594                 pkgmgrinfo_basic_free_application(info);
595                 sqlite3_finalize(stmt);
596                 return PMINFO_R_ERROR;
597         }
598
599         if (_appinfo_get_data_control(db, info->appid, &info->datacontrol)) {
600                 pkgmgrinfo_basic_free_application(info);
601                 sqlite3_finalize(stmt);
602                 return PMINFO_R_ERROR;
603         }
604
605         if (_appinfo_get_metadata(db, info->appid, &info->metadata)) {
606                 pkgmgrinfo_basic_free_application(info);
607                 sqlite3_finalize(stmt);
608                 return PMINFO_R_ERROR;
609         }
610
611         *application = info;
612
613         sqlite3_finalize(stmt);
614
615         return PMINFO_R_OK;
616 }
617
618 static int _appinfo_get_appinfo(const char *appid, uid_t uid,
619                 pkgmgr_appinfo_x **appinfo)
620 {
621         int ret;
622         sqlite3 *db;
623         const char *dbpath;
624         char *locale;
625         pkgmgr_appinfo_x *info;
626
627         dbpath = getUserPkgParserDBPathUID(uid);
628         if (dbpath == NULL)
629                 return PMINFO_R_ERROR;
630
631         locale = _get_system_locale();
632         if (locale == NULL)
633                 return PMINFO_R_ERROR;
634
635         ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
636         if (ret != SQLITE_OK) {
637                 _LOGE("failed to open db: %d", ret);
638                 free(locale);
639                 return PMINFO_R_ERROR;
640         }
641
642         info = calloc(1, sizeof(pkgmgr_appinfo_x));
643         if (info == NULL) {
644                 _LOGE("out of memory");
645                 free(locale);
646                 sqlite3_close_v2(db);
647                 return PMINFO_R_ERROR;
648         }
649
650         ret = _appinfo_get_application(db, appid, locale, &info->app_info);
651         if (ret != PMINFO_R_OK) {
652                 free(info);
653                 free(locale);
654                 sqlite3_close_v2(db);
655                 return ret;
656         }
657
658         info->locale = locale;
659         info->package = strdup(info->app_info->package);
660
661         *appinfo = info;
662
663         sqlite3_close_v2(db);
664
665         return ret;
666 }
667
668 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
669                 pkgmgrinfo_appinfo_h *handle)
670 {
671         int ret;
672
673         if (appid == NULL || handle == NULL) {
674                 LOGE("invalid parameter");
675                 return PMINFO_R_EINVAL;
676         }
677
678         ret = _appinfo_get_appinfo(appid, uid, (pkgmgr_appinfo_x **)handle);
679         if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
680                 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
681                                 (pkgmgr_appinfo_x **)handle);
682
683         if (ret != PMINFO_R_OK)
684                 _LOGE("failed to get appinfo of %s for user %d", appid, uid);
685
686         return ret;
687 }
688
689 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
690 {
691         return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
692 }
693
694 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
695                 pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb,
696                 void *user_data)
697 {
698         int ret;
699         pkgmgr_appinfo_x *info;
700         GList *list = NULL;
701         GList *tmp;
702         char *appid;
703         int stop = 0;
704
705         ret = _appinfo_get_filtered_list(filter, uid, &list);
706         if (ret != PMINFO_R_OK)
707                 return PMINFO_R_ERROR;
708
709         for (tmp = list; tmp; tmp = tmp->next) {
710                 appid = (char *)tmp->data;
711                 if (stop == 0) {
712                         ret = _appinfo_get_appinfo(appid, uid, &info);
713                         if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
714                                 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
715                                                 &info);
716                         if (ret != PMINFO_R_OK) {
717                                 free(appid);
718                                 continue;
719                         }
720                         if (app_list_cb(info, user_data) < 0)
721                                 stop = 1;
722                         pkgmgrinfo_appinfo_destroy_appinfo(info);
723                 }
724                 free(appid);
725         }
726
727         g_list_free(list);
728
729         return PMINFO_R_OK;
730 }
731
732 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
733                 pkgmgrinfo_app_component component,
734                 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
735 {
736         int ret;
737         pkgmgrinfo_appinfo_filter_h filter;
738         char *pkgid;
739         const char *comp_str = NULL;
740
741         if (handle == NULL || app_func == NULL) {
742                 LOGE("invalied parameter");
743                 return PMINFO_R_EINVAL;
744         }
745
746         if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
747                 LOGE("invalid parameter");
748                 return PMINFO_R_EINVAL;
749         }
750
751         if (pkgmgrinfo_appinfo_filter_create(&filter))
752                 return PMINFO_R_ERROR;
753
754         if (pkgmgrinfo_appinfo_filter_add_string(filter,
755                                 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
756                 pkgmgrinfo_appinfo_filter_destroy(filter);
757                 return PMINFO_R_ERROR;
758         }
759
760
761         switch (component) {
762         case PMINFO_UI_APP:
763                 comp_str = PMINFO_APPINFO_UI_APP;
764                 break;
765         case PMINFO_SVC_APP:
766                 comp_str = PMINFO_APPINFO_SVC_APP;
767                 break;
768         default:
769                 break;
770         }
771
772         if (comp_str) {
773                 if (pkgmgrinfo_appinfo_filter_add_string(filter,
774                                         PMINFO_APPINFO_PROP_APP_COMPONENT,
775                                         comp_str)) {
776                         pkgmgrinfo_appinfo_filter_destroy(filter);
777                         return PMINFO_R_ERROR;
778                 }
779         }
780
781         ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, app_func,
782                         user_data);
783
784         pkgmgrinfo_appinfo_filter_destroy(filter);
785
786         return ret;
787 }
788
789 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
790                                                 pkgmgrinfo_app_list_cb app_func, void *user_data)
791 {
792         return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
793 }
794
795 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
796 {
797         if (app_func == NULL) {
798                 LOGE("invalid parameter");
799                 return PMINFO_R_EINVAL;
800         }
801
802         return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
803                         user_data);
804 }
805
806 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
807 {
808         return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
809 }
810
811 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
812 {
813         if (app_func == NULL) {
814                 LOGE("invalid parameter");
815                 return PMINFO_R_EINVAL;
816         }
817
818         return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
819                         user_data);
820 }
821
822 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
823 {
824         return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
825 }
826
827 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
828 {
829         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
830
831         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
832         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
833
834         if (info->app_info == NULL || info->app_info->appid == NULL)
835                 return PMINFO_R_ERROR;
836         *appid = (char *)info->app_info->appid;
837
838         return PMINFO_R_OK;
839 }
840
841 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
842 {
843         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
844
845         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
846         retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
847
848         if (info->package == NULL)
849                 return PMINFO_R_ERROR;
850
851         *pkg_name = (char *)info->package;
852
853         return PMINFO_R_OK;
854 }
855
856 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
857 {
858         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
859
860         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
861         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
862
863         if (info->package == NULL)
864                 return PMINFO_R_ERROR;
865
866         *pkgid = (char *)info->package;
867
868         return PMINFO_R_OK;
869 }
870
871 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
872 {
873         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
874
875         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
876         retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
877
878         if (info->app_info == NULL || info->app_info->exec == NULL)
879                 return PMINFO_R_ERROR;
880         *exec = (char *)info->app_info->exec;
881
882         return PMINFO_R_OK;
883 }
884
885
886 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
887 {
888         const char *locale;
889         icon_x *ptr;
890         GList *tmp;
891         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
892
893         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
894         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
895
896         locale = info->locale;
897         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
898
899         if (info->app_info == NULL)
900                 return PMINFO_R_ERROR;
901
902         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
903                 ptr = (icon_x *)tmp->data;
904                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
905                                 strcmp(ptr->lang, locale))
906                         continue;
907                 *icon = (char *)ptr->text;
908                 return PMINFO_R_OK;
909         }
910
911         locale = DEFAULT_LOCALE;
912         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
913                 ptr = (icon_x *)tmp->data;
914                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
915                                 strcmp(ptr->lang, locale))
916                         continue;
917                 *icon = (char *)ptr->text;
918                 return PMINFO_R_OK;
919         }
920
921         return PMINFO_R_ERROR;
922 }
923
924
925 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
926 {
927         const char *locale;
928         label_x *ptr;
929         GList *tmp;
930         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
931
932         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
933         retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
934
935         locale = info->locale;
936         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
937
938         if (info->app_info == NULL)
939                 return PMINFO_R_ERROR;
940
941         for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
942                 ptr = (label_x *)tmp->data;
943                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
944                                 strcmp(ptr->lang, locale))
945                         continue;
946                 *label = (char *)ptr->text;
947                 return PMINFO_R_OK;
948         }
949
950         locale = DEFAULT_LOCALE;
951         for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
952                 ptr = (label_x *)tmp->data;
953                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
954                                 strcmp(ptr->lang, locale))
955                         continue;
956                 *label = (char *)ptr->text;
957                 return PMINFO_R_OK;
958         }
959
960         return PMINFO_R_ERROR;
961 }
962
963 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
964 {
965         char *result = NULL;
966         char *query = NULL;
967         sqlite3_stmt *stmt = NULL;
968         sqlite3 *db = NULL;
969         char *val;
970         const char *manifest_db;
971
972         manifest_db = getUserPkgParserDBPathUID(uid);
973         if (manifest_db == NULL) {
974                 _LOGE("Failed to get manifest db path");
975                 goto err;
976         }
977
978         if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
979                 _LOGE("DB open fail\n");
980                 goto err;
981         }
982
983         query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
984         if (query == NULL) {
985                 _LOGE("Out of memory");
986                 goto err;
987         }
988
989         if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
990                 _LOGE("prepare_v2 fail\n");
991                 goto err;
992         }
993
994         if (sqlite3_step(stmt) == SQLITE_ROW) {
995                 val = (char *)sqlite3_column_text(stmt, 0);
996                 if (val != NULL)
997                         result = strdup(val);
998         }
999
1000 err:
1001         sqlite3_finalize(stmt);
1002         sqlite3_free(query);
1003         sqlite3_close(db);
1004
1005         return result;
1006 }
1007
1008 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1009 {
1010         char *val;
1011
1012         retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1013
1014         val = _get_localed_label(appid, locale, uid);
1015         if (val == NULL)
1016                 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1017
1018         if (val == NULL)
1019                 return PMINFO_R_ERROR;
1020
1021         *label = val;
1022
1023         return PMINFO_R_OK;
1024 }
1025
1026 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1027 {
1028         return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
1029 }
1030
1031 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1032 {
1033         if ( strcasecmp(comp, "uiapp") == 0)
1034                 return PMINFO_UI_APP;
1035         else if ( strcasecmp(comp, "svcapp") == 0)
1036                 return PMINFO_SVC_APP;
1037         else
1038                 return -1;
1039 }
1040
1041 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1042 {
1043         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1044         int comp;
1045
1046         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1047         retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1048
1049         if (info->app_info == NULL)
1050                 return PMINFO_R_ERROR;
1051
1052         comp = __appcomponent_convert(info->app_info->component);
1053         if (comp < 0)
1054                 return PMINFO_R_ERROR;
1055
1056         *component = comp;
1057
1058         return PMINFO_R_OK;
1059 }
1060
1061 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1062 {
1063         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1064
1065         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1066         retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1067
1068         if (info->app_info == NULL || info->app_info->type == NULL)
1069                 return PMINFO_R_ERROR;
1070         *app_type = (char *)info->app_info->type;
1071
1072         return PMINFO_R_OK;
1073 }
1074
1075 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h  handle,
1076                                         int *operation_count, char ***operation)
1077 {
1078         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1079         retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1080         retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1081         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1082         *operation_count = data->operation_count;
1083         *operation = data->operation;
1084         return PMINFO_R_OK;
1085 }
1086
1087 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h  handle,
1088                                         int *uri_count, char ***uri)
1089 {
1090         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1091         retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1092         retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1093         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1094         *uri_count = data->uri_count;
1095         *uri = data->uri;
1096         return PMINFO_R_OK;
1097 }
1098
1099 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h  handle,
1100                                         int *mime_count, char ***mime)
1101 {
1102         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1103         retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1104         retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1105         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1106         *mime_count = data->mime_count;
1107         *mime = data->mime;
1108         return PMINFO_R_OK;
1109 }
1110
1111 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h  handle,
1112                                         int *subapp_count, char ***subapp)
1113 {
1114         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1115         retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1116         retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1117         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1118         *subapp_count = data->subapp_count;
1119         *subapp = data->subapp;
1120         return PMINFO_R_OK;
1121 }
1122
1123 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1124 {
1125         char *val;
1126         icon_x *ptr;
1127         GList *tmp;
1128         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1129
1130         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1131         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1132
1133         if (info->app_info == NULL)
1134                 return PMINFO_R_ERROR;
1135
1136         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1137                 ptr = (icon_x *)tmp->data;
1138                 if (ptr == NULL || ptr->section == NULL)
1139                         continue;
1140
1141                 val = (char *)ptr->section;
1142                 if (val && strcmp(val, "setting") == 0) {
1143                         *icon = (char *)ptr->text;
1144                         return PMINFO_R_OK;
1145                 }
1146         }
1147
1148         return PMINFO_R_ERROR;
1149 }
1150
1151
1152 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1153 {
1154         char *val;
1155         icon_x *ptr;
1156         GList *tmp;
1157         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1158
1159         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1160         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1161
1162         if (info->app_info == NULL)
1163                 return PMINFO_R_ERROR;
1164
1165         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1166                 ptr = (icon_x *)tmp->data;
1167                 if (ptr == NULL || ptr->section == NULL)
1168                         continue;
1169
1170                 val = (char *)ptr->section;
1171                 if (val && strcmp(val, "notification") == 0){
1172                         *icon = (char *)ptr->text;
1173                         return PMINFO_R_OK;
1174                 }
1175         }
1176
1177         return PMINFO_R_ERROR;
1178 }
1179
1180 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1181 {
1182         char *val;
1183         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1184
1185         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1186         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1187
1188         if (info->app_info == NULL || info->app_info->recentimage == NULL)
1189                 return PMINFO_R_ERROR;
1190
1191         val = (char *)info->app_info->recentimage;
1192         if (strcasecmp(val, "capture") == 0)
1193                 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1194         else if (strcasecmp(val, "icon") == 0)
1195                 *type = PMINFO_RECENTIMAGE_USE_ICON;
1196         else
1197                 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1198
1199         return PMINFO_R_OK;
1200 }
1201
1202 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1203 {
1204         char *val;
1205         image_x *ptr;
1206         GList *tmp;
1207         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1208
1209         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1210         retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1211
1212         if (info->app_info == NULL)
1213                 return PMINFO_R_ERROR;
1214
1215         for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1216                 ptr = (image_x *)tmp->data;
1217                 if (ptr == NULL || ptr->section == NULL)
1218                         continue;
1219
1220                 val = (char *)ptr->section;
1221                 if (val && strcmp(val, "preview") == 0) {
1222                         *preview_img = (char *)ptr->text;
1223                         return PMINFO_R_OK;
1224                 }
1225         }
1226
1227         return PMINFO_R_ERROR;
1228 }
1229
1230 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1231 {
1232         const char *val;
1233         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1234
1235         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1236         retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1237
1238         val = info->app_info->permission_type;
1239         if (val == NULL)
1240                 return PMINFO_R_ERROR;
1241
1242         if (strcmp(val, "signature") == 0)
1243                 *permission = PMINFO_PERMISSION_SIGNATURE;
1244         else if (strcmp(val, "privilege") == 0)
1245                 *permission = PMINFO_PERMISSION_PRIVILEGE;
1246         else
1247                 *permission = PMINFO_PERMISSION_NORMAL;
1248
1249         return PMINFO_R_OK;
1250 }
1251
1252 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1253 {
1254         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1255
1256         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1257         retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1258
1259         if (info->app_info == NULL || info->app_info->component_type == NULL)
1260                 return PMINFO_R_ERROR;
1261
1262         *component_type = (char *)info->app_info->component_type;
1263
1264         return PMINFO_R_OK;
1265 }
1266
1267 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1268 {
1269         char *val;
1270         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1271
1272         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1273         retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1274
1275         if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1276                 return PMINFO_R_ERROR;
1277
1278         val = (char *)info->app_info->hwacceleration;
1279         if (strcasecmp(val, "not-use-GL") == 0)
1280                 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
1281         else if (strcasecmp(val, "use-GL") == 0)
1282                 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
1283         else
1284                 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
1285
1286         return PMINFO_R_OK;
1287 }
1288
1289 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1290 {
1291         char *val;
1292         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1293
1294         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1295         retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1296
1297         if (info->app_info == NULL || info->app_info->screenreader == NULL)
1298                 return PMINFO_R_ERROR;
1299
1300         val = (char *)info->app_info->screenreader;
1301         if (strcasecmp(val, "screenreader-off") == 0)
1302                 *screenreader = PMINFO_SCREENREADER_OFF;
1303         else if (strcasecmp(val, "screenreader-on") == 0)
1304                 *screenreader = PMINFO_SCREENREADER_ON;
1305         else
1306                 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1307
1308         return PMINFO_R_OK;
1309 }
1310
1311 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1312 {
1313         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1314
1315         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1316         retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1317         retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1318
1319         if (info->app_info == NULL || info->app_info->portraitimg ||
1320                         info->app_info->landscapeimg == NULL)
1321                 return PMINFO_R_ERROR;
1322
1323         *portrait_img = (char *)info->app_info->portraitimg;
1324         *landscape_img = (char *)info->app_info->landscapeimg;
1325
1326         return PMINFO_R_OK;
1327 }
1328
1329 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h  handle, char **submode_mainid)
1330 {
1331         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1332
1333         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1334         retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1335
1336         if (info->app_info == NULL || info->app_info->submode_mainid == NULL)
1337                 return PMINFO_R_ERROR;
1338
1339         *submode_mainid = (char *)info->app_info->submode_mainid;
1340
1341         return PMINFO_R_OK;
1342 }
1343
1344 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
1345 {
1346         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1347         retvm_if(process_pool == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1348         char *val = NULL;
1349         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1350         val = (char *)info->app_info->process_pool;
1351         if (val) {
1352                 if (strcasecmp(val, "true") == 0)
1353                         *process_pool = 1;
1354                 else if (strcasecmp(val, "false") == 0)
1355                         *process_pool = 0;
1356                 else
1357                         *process_pool = 0;
1358         }
1359         return PMINFO_R_OK;
1360 }
1361
1362 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
1363 {
1364         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1365         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1366
1367         if (info->app_info && info->app_info->installed_storage){
1368                  if (strcmp(info->app_info->installed_storage,"installed_internal") == 0)
1369                         *storage = PMINFO_INTERNAL_STORAGE;
1370                  else if (strcmp(info->app_info->installed_storage,"installed_external") == 0)
1371                          *storage = PMINFO_EXTERNAL_STORAGE;
1372                  else
1373                          return PMINFO_R_ERROR;
1374         }else
1375                 return PMINFO_R_ERROR;
1376
1377         return PMINFO_R_OK;
1378 }
1379
1380 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
1381 {
1382         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1383
1384         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1385         retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1386
1387         if (info->app_info->launch_mode == NULL)
1388                 return PMINFO_R_ERROR;
1389
1390         *mode = (char *)(info->app_info->launch_mode);
1391
1392         return PMINFO_R_OK;
1393 }
1394
1395 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
1396 {
1397         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1398         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1399         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1400         retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1401
1402         int ret = PMINFO_R_OK;
1403         char *query = NULL;
1404         sqlite3_stmt *stmt = NULL;
1405
1406         /*open db*/
1407         ret = __open_manifest_db(uid, true);
1408         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1409
1410         /*Start constructing query*/
1411         query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
1412
1413         /*prepare query*/
1414         ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1415         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1416
1417         /*step query*/
1418         ret = sqlite3_step(stmt);
1419         tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1420
1421         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1422         *access = strdup((char *)sqlite3_column_text(stmt, 2));
1423
1424         ret = PMINFO_R_OK;
1425
1426 catch:
1427         sqlite3_free(query);
1428         sqlite3_finalize(stmt);
1429         __close_manifest_db();
1430         return ret;
1431 }
1432
1433 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
1434 {
1435         return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
1436 }
1437
1438 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
1439 {
1440         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1441         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1442
1443         int ret = PMINFO_R_OK;
1444         char *query = NULL;
1445         sqlite3_stmt *stmt = NULL;
1446
1447         /*open db*/
1448         ret = __open_manifest_db(uid, true);
1449         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1450
1451         /*Start constructing query*/
1452         query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
1453
1454         /*prepare query*/
1455         ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1456         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1457
1458         /*step query*/
1459         ret = sqlite3_step(stmt);
1460         tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1461
1462         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1463
1464         ret = PMINFO_R_OK;
1465
1466 catch:
1467         sqlite3_free(query);
1468         sqlite3_finalize(stmt);
1469         __close_manifest_db();
1470         return ret;
1471 }
1472
1473 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1474 {
1475         return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
1476 }
1477
1478 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
1479                         pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
1480 {
1481         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1482         retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1483         int ret = -1;
1484         permission_x *ptr;
1485         GList *tmp;
1486         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1487
1488         if (info->app_info == NULL)
1489                 return PMINFO_R_ERROR;
1490
1491         for (tmp = info->app_info->permission; tmp; tmp = tmp->next) {
1492                 ptr = (permission_x *)tmp->data;
1493                 if (ptr == NULL)
1494                         continue;
1495                 if (ptr->value) {
1496                         ret = permission_func(ptr->value, user_data);
1497                         if (ret < 0)
1498                                 break;
1499                 }
1500         }
1501         return PMINFO_R_OK;
1502 }
1503
1504 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
1505                         pkgmgrinfo_app_category_list_cb category_func, void *user_data)
1506 {
1507         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1508         retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1509         int ret = -1;
1510         const char *category;
1511         GList *tmp;
1512         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1513
1514         if (info->app_info == NULL)
1515                 return PMINFO_R_ERROR;
1516
1517         for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
1518                 category = (const char *)tmp->data;
1519                 if (category) {
1520                         ret = category_func(category, user_data);
1521                         if (ret < 0)
1522                                 break;
1523                 }
1524         }
1525         return PMINFO_R_OK;
1526 }
1527
1528 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
1529                         pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
1530 {
1531         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1532         retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1533         int ret = -1;
1534         metadata_x *ptr;
1535         GList *tmp;
1536         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1537
1538         if (info->app_info == NULL)
1539                 return PMINFO_R_ERROR;
1540
1541         for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
1542                 ptr = (metadata_x *)tmp->data;
1543                 if (ptr == NULL)
1544                         continue;
1545                 if (ptr->key) {
1546                         ret = metadata_func(ptr->key, ptr->value, user_data);
1547                         if (ret < 0)
1548                                 break;
1549                 }
1550         }
1551         return PMINFO_R_OK;
1552 }
1553
1554 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
1555                         pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1556 {
1557         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1558         retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1559         int ret;
1560         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1561         appcontrol_x *appcontrol;
1562         GList *tmp;
1563
1564         if (info->app_info == NULL)
1565                 return PMINFO_R_ERROR;
1566
1567         for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
1568                 appcontrol = (appcontrol_x *)tmp->data;
1569                 if (appcontrol == NULL)
1570                         continue;
1571                 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1572                 if (ret < 0)
1573                         break;
1574         }
1575
1576         return PMINFO_R_OK;
1577 }
1578
1579 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
1580 {
1581         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1582         retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1583         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1584
1585         if (info->app_info == NULL || info->app_info->nodisplay == NULL)
1586                 return PMINFO_R_ERROR;
1587
1588         *nodisplay = _get_bool_value(info->app_info->nodisplay);
1589
1590         return PMINFO_R_OK;
1591 }
1592
1593 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
1594 {
1595         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1596         retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1597         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1598
1599         if (info->app_info == NULL || info->app_info->multiple == NULL)
1600                 return PMINFO_R_ERROR;
1601
1602         *multiple = _get_bool_value(info->app_info->multiple);
1603
1604         return PMINFO_R_OK;
1605 }
1606
1607 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
1608 {
1609         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1610         retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1611         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1612
1613         if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
1614                 return PMINFO_R_ERROR;
1615
1616         *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
1617
1618         return PMINFO_R_OK;
1619 }
1620
1621 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h  handle, bool *taskmanage)
1622 {
1623         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1624         retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1625         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1626
1627         if (info->app_info == NULL || info->app_info->taskmanage == NULL)
1628                 return PMINFO_R_ERROR;
1629
1630         *taskmanage = _get_bool_value(info->app_info->taskmanage);
1631
1632         return PMINFO_R_OK;
1633 }
1634
1635 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h  handle, bool *enabled)
1636 {
1637         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1638         retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1639         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1640
1641         if (info->app_info == NULL || info->app_info->enabled == NULL)
1642                 return PMINFO_R_ERROR;
1643
1644         *enabled = _get_bool_value(info->app_info->enabled);
1645
1646         return PMINFO_R_OK;
1647 }
1648
1649 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h  handle, bool *onboot)
1650 {
1651         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1652         retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1653         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1654
1655         if (info->app_info == NULL || info->app_info->onboot == NULL)
1656                 return PMINFO_R_ERROR;
1657
1658         *onboot = _get_bool_value(info->app_info->onboot);
1659
1660         return PMINFO_R_OK;
1661 }
1662
1663 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h  handle, bool *autorestart)
1664 {
1665         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1666         retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1667         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1668
1669         if (info->app_info == NULL || info->app_info->autorestart == NULL)
1670                 return PMINFO_R_ERROR;
1671
1672         *autorestart = _get_bool_value(info->app_info->autorestart);
1673
1674         return PMINFO_R_OK;
1675 }
1676
1677 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h  handle, bool *mainapp)
1678 {
1679         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1680         retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1681         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1682
1683         if (info->app_info == NULL || info->app_info->mainapp == NULL)
1684                 return PMINFO_R_ERROR;
1685
1686         *mainapp = _get_bool_value(info->app_info->mainapp);
1687
1688         return PMINFO_R_OK;
1689 }
1690
1691 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
1692 {
1693         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1694         retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1695         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1696
1697         if (info->app_info == NULL || info->app_info->preload == NULL)
1698                 return PMINFO_R_ERROR;
1699
1700         *preload = _get_bool_value(info->app_info->preload);
1701
1702         return PMINFO_R_OK;
1703 }
1704
1705 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
1706 {
1707         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1708         retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1709         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1710
1711         if (info->app_info == NULL || info->app_info->submode == NULL)
1712                 return PMINFO_R_ERROR;
1713
1714         *submode = _get_bool_value(info->app_info->submode);
1715
1716         return PMINFO_R_OK;
1717 }
1718
1719 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
1720 {
1721         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1722         retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
1723         retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
1724
1725         const char *val;
1726         GList *tmp;
1727         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1728
1729         if (info->app_info == NULL)
1730                 return PMINFO_R_ERROR;
1731
1732         *exist = 0;
1733         for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
1734                 val = (const char *)tmp->data;
1735                 if (val == NULL)
1736                         continue;
1737                 if (strcasecmp(val, category) == 0) {
1738                         *exist = 1;
1739                         break;
1740                 }
1741         }
1742
1743         return PMINFO_R_OK;
1744 }
1745
1746 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
1747                 bool *ui_gadget)
1748 {
1749         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1750
1751         if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
1752                 _LOGE("invalid parameter");
1753                 return PMINFO_R_EINVAL;
1754         }
1755
1756         *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
1757
1758         return PMINFO_R_OK;
1759 }
1760
1761 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
1762                 bool *support_disable)
1763 {
1764         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1765
1766         if (info == NULL || info->app_info == NULL || support_disable == NULL) {
1767                 _LOGE("invalid parameter");
1768                 return PMINFO_R_EINVAL;
1769         }
1770
1771         *support_disable = _get_bool_value(info->app_info->support_disable);
1772
1773         return PMINFO_R_OK;
1774 }
1775
1776 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
1777 {
1778         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1779         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1780         __cleanup_appinfo(info);
1781         return PMINFO_R_OK;
1782 }
1783
1784 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
1785 {
1786         return (pkgmgrinfo_pkginfo_filter_create(handle));
1787 }
1788
1789 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
1790 {
1791         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1792 }
1793
1794 static gint __compare_func(gconstpointer data1, gconstpointer data2)
1795 {
1796         pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
1797         pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
1798         if (node1->prop == node2->prop)
1799                 return 0;
1800         else if (node1->prop > node2->prop)
1801                 return 1;
1802         else
1803                 return -1;
1804 }
1805
1806 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
1807                                 const char *property, const int value)
1808 {
1809         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1810         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1811         char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1812         char *val = NULL;
1813         GSList *link = NULL;
1814         int prop = -1;
1815         prop = _pminfo_appinfo_convert_to_prop_int(property);
1816         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
1817                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
1818                 _LOGE("Invalid Integer Property\n");
1819                 return PMINFO_R_EINVAL;
1820         }
1821         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1822         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1823         if (node == NULL) {
1824                 _LOGE("Out of Memory!!!\n");
1825                 return PMINFO_R_ERROR;
1826         }
1827         snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1828         val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1829         if (val == NULL) {
1830                 _LOGE("Out of Memory\n");
1831                 free(node);
1832                 node = NULL;
1833                 return PMINFO_R_ERROR;
1834         }
1835         node->prop = prop;
1836         node->value = val;
1837         /*If API is called multiple times for same property, we should override the previous values.
1838         Last value set will be used for filtering.*/
1839         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1840         if (link)
1841                 filter->list = g_slist_delete_link(filter->list, link);
1842         filter->list = g_slist_append(filter->list, (gpointer)node);
1843         return PMINFO_R_OK;
1844
1845 }
1846
1847 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
1848                                 const char *property, const bool value)
1849 {
1850         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1851         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1852         char *val = NULL;
1853         GSList *link = NULL;
1854         int prop = -1;
1855         prop = _pminfo_appinfo_convert_to_prop_bool(property);
1856         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
1857                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
1858                 _LOGE("Invalid Boolean Property\n");
1859                 return PMINFO_R_EINVAL;
1860         }
1861         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1862         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1863         if (node == NULL) {
1864                 _LOGE("Out of Memory!!!\n");
1865                 return PMINFO_R_ERROR;
1866         }
1867         if (value)
1868                 val = strndup("('true','True')", 15);
1869         else
1870                 val = strndup("('false','False')", 17);
1871         if (val == NULL) {
1872                 _LOGE("Out of Memory\n");
1873                 free(node);
1874                 node = NULL;
1875                 return PMINFO_R_ERROR;
1876         }
1877         node->prop = prop;
1878         node->value = val;
1879         /*If API is called multiple times for same property, we should override the previous values.
1880         Last value set will be used for filtering.*/
1881         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1882         if (link)
1883                 filter->list = g_slist_delete_link(filter->list, link);
1884         filter->list = g_slist_append(filter->list, (gpointer)node);
1885         return PMINFO_R_OK;
1886
1887 }
1888
1889 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
1890                                 const char *property, const char *value)
1891 {
1892         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1893         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1894         retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1895         char *val = NULL;
1896         pkgmgrinfo_node_x *ptr = NULL;
1897         char prev[PKG_STRING_LEN_MAX] = {'\0'};
1898         char temp[PKG_STRING_LEN_MAX] = {'\0'};
1899         GSList *link = NULL;
1900         int prop = -1;
1901         prop = _pminfo_appinfo_convert_to_prop_str(property);
1902         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
1903                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
1904                 _LOGE("Invalid String Property\n");
1905                 return PMINFO_R_EINVAL;
1906         }
1907         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1908         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1909         if (node == NULL) {
1910                 _LOGE("Out of Memory!!!\n");
1911                 return PMINFO_R_ERROR;
1912         }
1913         node->prop = prop;
1914         switch (prop) {
1915         case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
1916                 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
1917                         val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
1918                 else
1919                         val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
1920                 node->value = val;
1921                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1922                 if (link)
1923                         filter->list = g_slist_delete_link(filter->list, link);
1924                 filter->list = g_slist_append(filter->list, (gpointer)node);
1925                 break;
1926         case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
1927         case E_PMINFO_APPINFO_PROP_APP_OPERATION:
1928         case E_PMINFO_APPINFO_PROP_APP_URI:
1929         case E_PMINFO_APPINFO_PROP_APP_MIME:
1930                 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
1931                 if (val == NULL) {
1932                         _LOGE("Out of Memory\n");
1933                         free(node);
1934                         node = NULL;
1935                         return PMINFO_R_ERROR;
1936                 }
1937                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1938                 if (link) {
1939                         ptr = (pkgmgrinfo_node_x *)link->data;
1940                         strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
1941                         _LOGE("Previous value is %s\n", prev);
1942                         filter->list = g_slist_delete_link(filter->list, link);
1943                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
1944                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1945                         _LOGE("New value is %s\n", val);
1946                         node->value = val;
1947                         filter->list = g_slist_append(filter->list, (gpointer)node);
1948                         memset(temp, '\0', PKG_STRING_LEN_MAX);
1949                 } else {
1950                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
1951                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1952                         _LOGE("First value is %s\n", val);
1953                         node->value = val;
1954                         filter->list = g_slist_append(filter->list, (gpointer)node);
1955                         memset(temp, '\0', PKG_STRING_LEN_MAX);
1956                 }
1957                 break;
1958         default:
1959                 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
1960                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1961                 if (link)
1962                         filter->list = g_slist_delete_link(filter->list, link);
1963                 filter->list = g_slist_append(filter->list, (gpointer)node);
1964                 break;
1965         }
1966         return PMINFO_R_OK;
1967 }
1968
1969 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
1970 {
1971         int ret;
1972         GList *list = NULL;
1973
1974         if (handle == NULL || count == NULL) {
1975                 _LOGE("invalid parameter");
1976                 return PMINFO_R_EINVAL;
1977         }
1978
1979         ret = _appinfo_get_filtered_list(handle, uid, &list);
1980         if (ret != PMINFO_R_OK)
1981                 return PMINFO_R_ERROR;
1982
1983         *count = g_list_length(list);
1984
1985         g_list_free_full(list, free);
1986
1987         return PMINFO_R_OK;
1988 }
1989
1990 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
1991 {
1992         return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
1993 }
1994
1995 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
1996                 pkgmgrinfo_appinfo_filter_h handle,
1997                 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
1998 {
1999         if (handle == NULL || app_cb == NULL) {
2000                 LOGE("invalid parameter");
2001                 return PMINFO_R_EINVAL;
2002         }
2003
2004         return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2005                         user_data);
2006 }
2007
2008 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
2009                                 pkgmgrinfo_app_list_cb app_cb, void * user_data)
2010 {
2011         return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
2012 }
2013
2014 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
2015 {
2016         return (pkgmgrinfo_pkginfo_filter_create(handle));
2017 }
2018
2019 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
2020 {
2021         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2022 }
2023
2024 API int pkgmgrinfo_appinfo_metadata_filter_add(
2025                 pkgmgrinfo_appinfo_metadata_filter_h handle,
2026                 const char *key, const char *value)
2027 {
2028         int ret;
2029
2030         ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2031                         PMINFO_APPINFO_PROP_APP_METADATA_KEY, key);
2032         if (ret != PMINFO_R_OK)
2033                 return ret;
2034
2035         /* value can be NULL.
2036          * In that case all apps with specified key should be displayed
2037          */
2038         if (value) {
2039                 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2040                                 PMINFO_APPINFO_PROP_APP_METADATA_VALUE, value);
2041                 if (ret != PMINFO_R_OK)
2042                         return ret;
2043         }
2044
2045         return PMINFO_R_OK;
2046 }
2047
2048 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2049                 pkgmgrinfo_appinfo_metadata_filter_h handle,
2050                 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2051 {
2052         if (handle == NULL || app_cb == NULL) {
2053                 LOGE("invalid parameter");
2054                 return PMINFO_R_EINVAL;
2055         }
2056
2057         return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2058                         user_data);
2059 }
2060
2061 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
2062                 pkgmgrinfo_appinfo_metadata_filter_h handle,
2063                 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2064 {
2065         return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
2066                         user_data, GLOBAL_USER);
2067 }
2068
2069 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2070 {
2071         const char *val;
2072         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2073
2074         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2075         retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2076
2077         val = info->app_info->guestmode_visibility;
2078         *status = _get_bool_value(val);
2079         return PMINFO_R_OK;
2080 }