Add missing api from Tizen 2.4
[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                                 !strcasecmp(ptr->text, "(null)") ||
906                                 strcmp(ptr->lang, locale))
907                         continue;
908                 *icon = (char *)ptr->text;
909                 return PMINFO_R_OK;
910         }
911
912         locale = DEFAULT_LOCALE;
913         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
914                 ptr = (icon_x *)tmp->data;
915                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
916                                 strcmp(ptr->lang, locale))
917                         continue;
918                 *icon = (char *)ptr->text;
919                 return PMINFO_R_OK;
920         }
921
922         return PMINFO_R_ERROR;
923 }
924
925
926 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
927 {
928         const char *locale;
929         label_x *ptr;
930         GList *tmp;
931         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
932
933         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
934         retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
935
936         locale = info->locale;
937         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
938
939         if (info->app_info == NULL)
940                 return PMINFO_R_ERROR;
941
942         for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
943                 ptr = (label_x *)tmp->data;
944                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
945                                 strcmp(ptr->lang, locale))
946                         continue;
947                 *label = (char *)ptr->text;
948                 return PMINFO_R_OK;
949         }
950
951         locale = DEFAULT_LOCALE;
952         for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
953                 ptr = (label_x *)tmp->data;
954                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
955                                 strcmp(ptr->lang, locale))
956                         continue;
957                 *label = (char *)ptr->text;
958                 return PMINFO_R_OK;
959         }
960
961         return PMINFO_R_ERROR;
962 }
963
964 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
965 {
966         char *result = NULL;
967         char *query = NULL;
968         sqlite3_stmt *stmt = NULL;
969         sqlite3 *db = NULL;
970         char *val;
971         const char *manifest_db;
972
973         manifest_db = getUserPkgParserDBPathUID(uid);
974         if (manifest_db == NULL) {
975                 _LOGE("Failed to get manifest db path");
976                 goto err;
977         }
978
979         if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
980                 _LOGE("DB open fail\n");
981                 goto err;
982         }
983
984         query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
985         if (query == NULL) {
986                 _LOGE("Out of memory");
987                 goto err;
988         }
989
990         if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
991                 _LOGE("prepare_v2 fail\n");
992                 goto err;
993         }
994
995         if (sqlite3_step(stmt) == SQLITE_ROW) {
996                 val = (char *)sqlite3_column_text(stmt, 0);
997                 if (val != NULL)
998                         result = strdup(val);
999         }
1000
1001 err:
1002         sqlite3_finalize(stmt);
1003         sqlite3_free(query);
1004         sqlite3_close(db);
1005
1006         return result;
1007 }
1008
1009 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1010 {
1011         char *val;
1012
1013         retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1014
1015         val = _get_localed_label(appid, locale, uid);
1016         if (val == NULL)
1017                 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1018
1019         if (val == NULL)
1020                 return PMINFO_R_ERROR;
1021
1022         *label = val;
1023
1024         return PMINFO_R_OK;
1025 }
1026
1027 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1028 {
1029         return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
1030 }
1031
1032 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1033 {
1034         if ( strcasecmp(comp, "uiapp") == 0)
1035                 return PMINFO_UI_APP;
1036         else if ( strcasecmp(comp, "svcapp") == 0)
1037                 return PMINFO_SVC_APP;
1038         else
1039                 return -1;
1040 }
1041
1042 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1043 {
1044         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1045         int comp;
1046
1047         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1048         retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1049
1050         if (info->app_info == NULL)
1051                 return PMINFO_R_ERROR;
1052
1053         comp = __appcomponent_convert(info->app_info->component);
1054         if (comp < 0)
1055                 return PMINFO_R_ERROR;
1056
1057         *component = comp;
1058
1059         return PMINFO_R_OK;
1060 }
1061
1062 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1063 {
1064         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1065
1066         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1067         retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1068
1069         if (info->app_info == NULL || info->app_info->type == NULL)
1070                 return PMINFO_R_ERROR;
1071         *app_type = (char *)info->app_info->type;
1072
1073         return PMINFO_R_OK;
1074 }
1075
1076 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h  handle,
1077                                         int *operation_count, char ***operation)
1078 {
1079         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1080         retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1081         retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1082         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1083         *operation_count = data->operation_count;
1084         *operation = data->operation;
1085         return PMINFO_R_OK;
1086 }
1087
1088 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h  handle,
1089                                         int *uri_count, char ***uri)
1090 {
1091         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1092         retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1093         retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1094         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1095         *uri_count = data->uri_count;
1096         *uri = data->uri;
1097         return PMINFO_R_OK;
1098 }
1099
1100 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h  handle,
1101                                         int *mime_count, char ***mime)
1102 {
1103         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1104         retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1105         retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1106         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1107         *mime_count = data->mime_count;
1108         *mime = data->mime;
1109         return PMINFO_R_OK;
1110 }
1111
1112 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h  handle,
1113                                         int *subapp_count, char ***subapp)
1114 {
1115         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1116         retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1117         retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1118         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1119         *subapp_count = data->subapp_count;
1120         *subapp = data->subapp;
1121         return PMINFO_R_OK;
1122 }
1123
1124 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1125 {
1126         char *val;
1127         icon_x *ptr;
1128         GList *tmp;
1129         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1130
1131         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1132         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1133
1134         if (info->app_info == NULL)
1135                 return PMINFO_R_ERROR;
1136
1137         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1138                 ptr = (icon_x *)tmp->data;
1139                 if (ptr == NULL || ptr->section == NULL)
1140                         continue;
1141
1142                 val = (char *)ptr->section;
1143                 if (val && strcmp(val, "setting") == 0) {
1144                         *icon = (char *)ptr->text;
1145                         return PMINFO_R_OK;
1146                 }
1147         }
1148
1149         return PMINFO_R_ERROR;
1150 }
1151
1152
1153 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1154 {
1155         char *val;
1156         icon_x *ptr;
1157         GList *tmp;
1158         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1159
1160         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1161         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1162
1163         if (info->app_info == NULL)
1164                 return PMINFO_R_ERROR;
1165
1166         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1167                 ptr = (icon_x *)tmp->data;
1168                 if (ptr == NULL || ptr->section == NULL)
1169                         continue;
1170
1171                 val = (char *)ptr->section;
1172                 if (val && strcmp(val, "notification") == 0){
1173                         *icon = (char *)ptr->text;
1174                         return PMINFO_R_OK;
1175                 }
1176         }
1177
1178         return PMINFO_R_ERROR;
1179 }
1180
1181 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1182 {
1183         char *val;
1184         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1185
1186         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1187         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1188
1189         if (info->app_info == NULL || info->app_info->recentimage == NULL)
1190                 return PMINFO_R_ERROR;
1191
1192         val = (char *)info->app_info->recentimage;
1193         if (strcasecmp(val, "capture") == 0)
1194                 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1195         else if (strcasecmp(val, "icon") == 0)
1196                 *type = PMINFO_RECENTIMAGE_USE_ICON;
1197         else
1198                 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1199
1200         return PMINFO_R_OK;
1201 }
1202
1203 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1204 {
1205         char *val;
1206         image_x *ptr;
1207         GList *tmp;
1208         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1209
1210         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1211         retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1212
1213         if (info->app_info == NULL)
1214                 return PMINFO_R_ERROR;
1215
1216         for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1217                 ptr = (image_x *)tmp->data;
1218                 if (ptr == NULL || ptr->section == NULL)
1219                         continue;
1220
1221                 val = (char *)ptr->section;
1222                 if (val && strcmp(val, "preview") == 0) {
1223                         *preview_img = (char *)ptr->text;
1224                         return PMINFO_R_OK;
1225                 }
1226         }
1227
1228         return PMINFO_R_ERROR;
1229 }
1230
1231 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1232 {
1233         const char *val;
1234         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1235
1236         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1237         retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1238
1239         val = info->app_info->permission_type;
1240         if (val == NULL)
1241                 return PMINFO_R_ERROR;
1242
1243         if (strcmp(val, "signature") == 0)
1244                 *permission = PMINFO_PERMISSION_SIGNATURE;
1245         else if (strcmp(val, "privilege") == 0)
1246                 *permission = PMINFO_PERMISSION_PRIVILEGE;
1247         else
1248                 *permission = PMINFO_PERMISSION_NORMAL;
1249
1250         return PMINFO_R_OK;
1251 }
1252
1253 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1254 {
1255         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1256
1257         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1258         retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1259
1260         if (info->app_info == NULL || info->app_info->component_type == NULL)
1261                 return PMINFO_R_ERROR;
1262
1263         *component_type = (char *)info->app_info->component_type;
1264
1265         return PMINFO_R_OK;
1266 }
1267
1268 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1269 {
1270         char *val;
1271         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1272
1273         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1274         retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1275
1276         if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1277                 return PMINFO_R_ERROR;
1278
1279         val = (char *)info->app_info->hwacceleration;
1280         if (strcasecmp(val, "not-use-GL") == 0)
1281                 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
1282         else if (strcasecmp(val, "use-GL") == 0)
1283                 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
1284         else
1285                 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
1286
1287         return PMINFO_R_OK;
1288 }
1289
1290 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1291 {
1292         char *val;
1293         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1294
1295         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1296         retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1297
1298         if (info->app_info == NULL || info->app_info->screenreader == NULL)
1299                 return PMINFO_R_ERROR;
1300
1301         val = (char *)info->app_info->screenreader;
1302         if (strcasecmp(val, "screenreader-off") == 0)
1303                 *screenreader = PMINFO_SCREENREADER_OFF;
1304         else if (strcasecmp(val, "screenreader-on") == 0)
1305                 *screenreader = PMINFO_SCREENREADER_ON;
1306         else
1307                 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1308
1309         return PMINFO_R_OK;
1310 }
1311
1312 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1313 {
1314         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1315
1316         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1317         retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1318         retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1319
1320         if (info->app_info == NULL || info->app_info->portraitimg ||
1321                         info->app_info->landscapeimg == NULL)
1322                 return PMINFO_R_ERROR;
1323
1324         *portrait_img = (char *)info->app_info->portraitimg;
1325         *landscape_img = (char *)info->app_info->landscapeimg;
1326
1327         return PMINFO_R_OK;
1328 }
1329
1330 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
1331 {
1332         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1333
1334         if (handle == NULL || effectimage_type == NULL) {
1335                 LOGE("invalid parameter");
1336                 return PMINFO_R_EINVAL;
1337         }
1338
1339         if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
1340                 return PMINFO_R_ERROR;
1341
1342         *effectimage_type = (char *)info->app_info->effectimage_type;
1343
1344         return PMINFO_R_OK;
1345 }
1346
1347 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h  handle, char **submode_mainid)
1348 {
1349         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1350
1351         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1352         retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1353
1354         if (info->app_info == NULL || info->app_info->submode_mainid == NULL)
1355                 return PMINFO_R_ERROR;
1356
1357         *submode_mainid = (char *)info->app_info->submode_mainid;
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_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
1396 {
1397         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1398
1399         if (handle == NULL || alias_appid == NULL) {
1400                 LOGE("invalid parameter");
1401                 return PMINFO_R_EINVAL;
1402         }
1403
1404         if (info->app_info == NULL || info->app_info->alias_appid == NULL)
1405                 return PMINFO_R_ERROR;
1406
1407         *alias_appid = (char *)info->app_info->alias_appid;
1408
1409         return PMINFO_R_OK;
1410 }
1411
1412 API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
1413 {
1414         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1415
1416         if (handle == NULL || effective_appid == NULL) {
1417                 LOGE("invalid parameter");
1418                 return PMINFO_R_EINVAL;
1419         }
1420
1421         if (info->app_info == NULL || info->app_info->effective_appid == NULL)
1422                 return PMINFO_R_ERROR;
1423
1424         *effective_appid = (char *)info->app_info->effective_appid;
1425
1426         return PMINFO_R_OK;
1427 }
1428
1429 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
1430 {
1431         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1432         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1433         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1434         retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1435
1436         int ret = PMINFO_R_OK;
1437         char *query = NULL;
1438         sqlite3_stmt *stmt = NULL;
1439
1440         /*open db*/
1441         ret = __open_manifest_db(uid, true);
1442         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1443
1444         /*Start constructing query*/
1445         query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
1446
1447         /*prepare query*/
1448         ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1449         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1450
1451         /*step query*/
1452         ret = sqlite3_step(stmt);
1453         tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1454
1455         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1456         *access = strdup((char *)sqlite3_column_text(stmt, 2));
1457
1458         ret = PMINFO_R_OK;
1459
1460 catch:
1461         sqlite3_free(query);
1462         sqlite3_finalize(stmt);
1463         __close_manifest_db();
1464         return ret;
1465 }
1466
1467 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
1468 {
1469         return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
1470 }
1471
1472 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
1473 {
1474         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1475         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1476
1477         int ret = PMINFO_R_OK;
1478         char *query = NULL;
1479         sqlite3_stmt *stmt = NULL;
1480
1481         /*open db*/
1482         ret = __open_manifest_db(uid, true);
1483         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1484
1485         /*Start constructing query*/
1486         query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
1487
1488         /*prepare query*/
1489         ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1490         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1491
1492         /*step query*/
1493         ret = sqlite3_step(stmt);
1494         tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1495
1496         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1497
1498         ret = PMINFO_R_OK;
1499
1500 catch:
1501         sqlite3_free(query);
1502         sqlite3_finalize(stmt);
1503         __close_manifest_db();
1504         return ret;
1505 }
1506
1507 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1508 {
1509         return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
1510 }
1511
1512 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
1513                         pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
1514 {
1515         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1516         retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1517         int ret = -1;
1518         permission_x *ptr;
1519         GList *tmp;
1520         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1521
1522         if (info->app_info == NULL)
1523                 return PMINFO_R_ERROR;
1524
1525         for (tmp = info->app_info->permission; tmp; tmp = tmp->next) {
1526                 ptr = (permission_x *)tmp->data;
1527                 if (ptr == NULL)
1528                         continue;
1529                 if (ptr->value) {
1530                         ret = permission_func(ptr->value, user_data);
1531                         if (ret < 0)
1532                                 break;
1533                 }
1534         }
1535         return PMINFO_R_OK;
1536 }
1537
1538 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
1539                         pkgmgrinfo_app_category_list_cb category_func, void *user_data)
1540 {
1541         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1542         retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1543         int ret = -1;
1544         const char *category;
1545         GList *tmp;
1546         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1547
1548         if (info->app_info == NULL)
1549                 return PMINFO_R_ERROR;
1550
1551         for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
1552                 category = (const char *)tmp->data;
1553                 if (category) {
1554                         ret = category_func(category, user_data);
1555                         if (ret < 0)
1556                                 break;
1557                 }
1558         }
1559         return PMINFO_R_OK;
1560 }
1561
1562 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
1563                         pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
1564 {
1565         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1566         retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1567         int ret = -1;
1568         metadata_x *ptr;
1569         GList *tmp;
1570         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1571
1572         if (info->app_info == NULL)
1573                 return PMINFO_R_ERROR;
1574
1575         for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
1576                 ptr = (metadata_x *)tmp->data;
1577                 if (ptr == NULL)
1578                         continue;
1579                 if (ptr->key) {
1580                         ret = metadata_func(ptr->key, ptr->value, user_data);
1581                         if (ret < 0)
1582                                 break;
1583                 }
1584         }
1585         return PMINFO_R_OK;
1586 }
1587
1588 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
1589                         pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1590 {
1591         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1592         retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1593         int ret;
1594         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1595         appcontrol_x *appcontrol;
1596         GList *tmp;
1597
1598         if (info->app_info == NULL)
1599                 return PMINFO_R_ERROR;
1600
1601         for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
1602                 appcontrol = (appcontrol_x *)tmp->data;
1603                 if (appcontrol == NULL)
1604                         continue;
1605                 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1606                 if (ret < 0)
1607                         break;
1608         }
1609
1610         return PMINFO_R_OK;
1611 }
1612
1613 API int pkgmgrinfo_appinfo_foreach_background_category(
1614                 pkgmgrinfo_appinfo_h handle,
1615                 pkgmgrinfo_app_background_category_list_cb category_func,
1616                 void *user_data)
1617 {
1618         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1619         GList *tmp;
1620         char *category;
1621
1622         if (handle == NULL || category_func == NULL || info->app_info == NULL) {
1623                 LOGE("invalid parameter");
1624                 return PMINFO_R_EINVAL;
1625         }
1626
1627         for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
1628                 category = (char *)tmp->data;
1629                 if (category == NULL)
1630                         continue;
1631
1632                 if (category_func(category, user_data) < 0)
1633                         break;
1634         }
1635
1636         return PMINFO_R_OK;
1637 }
1638
1639 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
1640 {
1641         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1642         retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1643         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1644
1645         if (info->app_info == NULL || info->app_info->nodisplay == NULL)
1646                 return PMINFO_R_ERROR;
1647
1648         *nodisplay = _get_bool_value(info->app_info->nodisplay);
1649
1650         return PMINFO_R_OK;
1651 }
1652
1653 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
1654 {
1655         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1656         retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1657         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1658
1659         if (info->app_info == NULL || info->app_info->multiple == NULL)
1660                 return PMINFO_R_ERROR;
1661
1662         *multiple = _get_bool_value(info->app_info->multiple);
1663
1664         return PMINFO_R_OK;
1665 }
1666
1667 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
1668 {
1669         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1670         retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1671         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1672
1673         if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
1674                 return PMINFO_R_ERROR;
1675
1676         *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
1677
1678         return PMINFO_R_OK;
1679 }
1680
1681 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h  handle, bool *taskmanage)
1682 {
1683         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1684         retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1685         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1686
1687         if (info->app_info == NULL || info->app_info->taskmanage == NULL)
1688                 return PMINFO_R_ERROR;
1689
1690         *taskmanage = _get_bool_value(info->app_info->taskmanage);
1691
1692         return PMINFO_R_OK;
1693 }
1694
1695 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h  handle, bool *enabled)
1696 {
1697         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1698         retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1699         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1700
1701         if (info->app_info == NULL || info->app_info->enabled == NULL)
1702                 return PMINFO_R_ERROR;
1703
1704         *enabled = _get_bool_value(info->app_info->enabled);
1705
1706         return PMINFO_R_OK;
1707 }
1708
1709 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h  handle, bool *onboot)
1710 {
1711         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1712         retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1713         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1714
1715         if (info->app_info == NULL || info->app_info->onboot == NULL)
1716                 return PMINFO_R_ERROR;
1717
1718         *onboot = _get_bool_value(info->app_info->onboot);
1719
1720         return PMINFO_R_OK;
1721 }
1722
1723 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h  handle, bool *autorestart)
1724 {
1725         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1726         retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1727         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1728
1729         if (info->app_info == NULL || info->app_info->autorestart == NULL)
1730                 return PMINFO_R_ERROR;
1731
1732         *autorestart = _get_bool_value(info->app_info->autorestart);
1733
1734         return PMINFO_R_OK;
1735 }
1736
1737 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h  handle, bool *mainapp)
1738 {
1739         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1740         retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1741         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1742
1743         if (info->app_info == NULL || info->app_info->mainapp == NULL)
1744                 return PMINFO_R_ERROR;
1745
1746         *mainapp = _get_bool_value(info->app_info->mainapp);
1747
1748         return PMINFO_R_OK;
1749 }
1750
1751 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
1752 {
1753         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1754         retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1755         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1756
1757         if (info->app_info == NULL || info->app_info->preload == NULL)
1758                 return PMINFO_R_ERROR;
1759
1760         *preload = _get_bool_value(info->app_info->preload);
1761
1762         return PMINFO_R_OK;
1763 }
1764
1765 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
1766 {
1767         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1768         retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1769         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1770
1771         if (info->app_info == NULL || info->app_info->submode == NULL)
1772                 return PMINFO_R_ERROR;
1773
1774         *submode = _get_bool_value(info->app_info->submode);
1775
1776         return PMINFO_R_OK;
1777 }
1778
1779 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
1780 {
1781         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1782
1783         if (handle == NULL || process_pool == NULL) {
1784                 LOGE("invalid parameter");
1785                 return PMINFO_R_EINVAL;
1786         }
1787
1788         if (info->app_info == NULL)
1789                 return PMINFO_R_ERROR;
1790
1791         *process_pool = _get_bool_value(info->app_info->process_pool);
1792
1793         return PMINFO_R_OK;
1794 }
1795
1796 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
1797 {
1798         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1799         retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
1800         retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
1801
1802         const char *val;
1803         GList *tmp;
1804         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1805
1806         if (info->app_info == NULL)
1807                 return PMINFO_R_ERROR;
1808
1809         *exist = 0;
1810         for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
1811                 val = (const char *)tmp->data;
1812                 if (val == NULL)
1813                         continue;
1814                 if (strcasecmp(val, category) == 0) {
1815                         *exist = 1;
1816                         break;
1817                 }
1818         }
1819
1820         return PMINFO_R_OK;
1821 }
1822
1823 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
1824                 bool *ui_gadget)
1825 {
1826         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1827
1828         if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
1829                 _LOGE("invalid parameter");
1830                 return PMINFO_R_EINVAL;
1831         }
1832
1833         *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
1834
1835         return PMINFO_R_OK;
1836 }
1837
1838 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
1839                 bool *support_disable)
1840 {
1841         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1842
1843         if (info == NULL || info->app_info == NULL || support_disable == NULL) {
1844                 _LOGE("invalid parameter");
1845                 return PMINFO_R_EINVAL;
1846         }
1847
1848         *support_disable = _get_bool_value(info->app_info->support_disable);
1849
1850         return PMINFO_R_OK;
1851 }
1852
1853 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
1854 {
1855         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1856         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1857         __cleanup_appinfo(info);
1858         return PMINFO_R_OK;
1859 }
1860
1861 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
1862 {
1863         return (pkgmgrinfo_pkginfo_filter_create(handle));
1864 }
1865
1866 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
1867 {
1868         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1869 }
1870
1871 static gint __compare_func(gconstpointer data1, gconstpointer data2)
1872 {
1873         pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
1874         pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
1875         if (node1->prop == node2->prop)
1876                 return 0;
1877         else if (node1->prop > node2->prop)
1878                 return 1;
1879         else
1880                 return -1;
1881 }
1882
1883 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
1884                                 const char *property, const int value)
1885 {
1886         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1887         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1888         char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1889         char *val = NULL;
1890         GSList *link = NULL;
1891         int prop = -1;
1892         prop = _pminfo_appinfo_convert_to_prop_int(property);
1893         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
1894                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
1895                 _LOGE("Invalid Integer Property\n");
1896                 return PMINFO_R_EINVAL;
1897         }
1898         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1899         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1900         if (node == NULL) {
1901                 _LOGE("Out of Memory!!!\n");
1902                 return PMINFO_R_ERROR;
1903         }
1904         snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1905         val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1906         if (val == NULL) {
1907                 _LOGE("Out of Memory\n");
1908                 free(node);
1909                 node = NULL;
1910                 return PMINFO_R_ERROR;
1911         }
1912         node->prop = prop;
1913         node->value = val;
1914         /*If API is called multiple times for same property, we should override the previous values.
1915         Last value set will be used for filtering.*/
1916         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1917         if (link)
1918                 filter->list = g_slist_delete_link(filter->list, link);
1919         filter->list = g_slist_append(filter->list, (gpointer)node);
1920         return PMINFO_R_OK;
1921
1922 }
1923
1924 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
1925                                 const char *property, const bool value)
1926 {
1927         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1928         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1929         char *val = NULL;
1930         GSList *link = NULL;
1931         int prop = -1;
1932         prop = _pminfo_appinfo_convert_to_prop_bool(property);
1933         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
1934                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
1935                 _LOGE("Invalid Boolean Property\n");
1936                 return PMINFO_R_EINVAL;
1937         }
1938         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1939         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1940         if (node == NULL) {
1941                 _LOGE("Out of Memory!!!\n");
1942                 return PMINFO_R_ERROR;
1943         }
1944         if (value)
1945                 val = strndup("('true','True')", 15);
1946         else
1947                 val = strndup("('false','False')", 17);
1948         if (val == NULL) {
1949                 _LOGE("Out of Memory\n");
1950                 free(node);
1951                 node = NULL;
1952                 return PMINFO_R_ERROR;
1953         }
1954         node->prop = prop;
1955         node->value = val;
1956         /*If API is called multiple times for same property, we should override the previous values.
1957         Last value set will be used for filtering.*/
1958         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1959         if (link)
1960                 filter->list = g_slist_delete_link(filter->list, link);
1961         filter->list = g_slist_append(filter->list, (gpointer)node);
1962         return PMINFO_R_OK;
1963
1964 }
1965
1966 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
1967                                 const char *property, const char *value)
1968 {
1969         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1970         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1971         retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1972         char *val = NULL;
1973         pkgmgrinfo_node_x *ptr = NULL;
1974         char prev[PKG_STRING_LEN_MAX] = {'\0'};
1975         char temp[PKG_STRING_LEN_MAX] = {'\0'};
1976         GSList *link = NULL;
1977         int prop = -1;
1978         prop = _pminfo_appinfo_convert_to_prop_str(property);
1979         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
1980                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
1981                 _LOGE("Invalid String Property\n");
1982                 return PMINFO_R_EINVAL;
1983         }
1984         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1985         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1986         if (node == NULL) {
1987                 _LOGE("Out of Memory!!!\n");
1988                 return PMINFO_R_ERROR;
1989         }
1990         node->prop = prop;
1991         switch (prop) {
1992         case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
1993                 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
1994                         val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
1995                 else
1996                         val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
1997                 node->value = val;
1998                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1999                 if (link)
2000                         filter->list = g_slist_delete_link(filter->list, link);
2001                 filter->list = g_slist_append(filter->list, (gpointer)node);
2002                 break;
2003         case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
2004         case E_PMINFO_APPINFO_PROP_APP_OPERATION:
2005         case E_PMINFO_APPINFO_PROP_APP_URI:
2006         case E_PMINFO_APPINFO_PROP_APP_MIME:
2007                 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
2008                 if (val == NULL) {
2009                         _LOGE("Out of Memory\n");
2010                         free(node);
2011                         node = NULL;
2012                         return PMINFO_R_ERROR;
2013                 }
2014                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2015                 if (link) {
2016                         ptr = (pkgmgrinfo_node_x *)link->data;
2017                         strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
2018                         _LOGE("Previous value is %s\n", prev);
2019                         filter->list = g_slist_delete_link(filter->list, link);
2020                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
2021                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
2022                         _LOGE("New value is %s\n", val);
2023                         node->value = val;
2024                         filter->list = g_slist_append(filter->list, (gpointer)node);
2025                         memset(temp, '\0', PKG_STRING_LEN_MAX);
2026                 } else {
2027                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
2028                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
2029                         _LOGE("First value is %s\n", val);
2030                         node->value = val;
2031                         filter->list = g_slist_append(filter->list, (gpointer)node);
2032                         memset(temp, '\0', PKG_STRING_LEN_MAX);
2033                 }
2034                 break;
2035         default:
2036                 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
2037                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2038                 if (link)
2039                         filter->list = g_slist_delete_link(filter->list, link);
2040                 filter->list = g_slist_append(filter->list, (gpointer)node);
2041                 break;
2042         }
2043         return PMINFO_R_OK;
2044 }
2045
2046 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
2047 {
2048         int ret;
2049         GList *list = NULL;
2050
2051         if (handle == NULL || count == NULL) {
2052                 _LOGE("invalid parameter");
2053                 return PMINFO_R_EINVAL;
2054         }
2055
2056         ret = _appinfo_get_filtered_list(handle, uid, &list);
2057         if (ret != PMINFO_R_OK)
2058                 return PMINFO_R_ERROR;
2059
2060         *count = g_list_length(list);
2061
2062         g_list_free_full(list, free);
2063
2064         return PMINFO_R_OK;
2065 }
2066
2067 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
2068 {
2069         return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
2070 }
2071
2072 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
2073                 pkgmgrinfo_appinfo_filter_h handle,
2074                 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2075 {
2076         if (handle == NULL || app_cb == NULL) {
2077                 LOGE("invalid parameter");
2078                 return PMINFO_R_EINVAL;
2079         }
2080
2081         return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2082                         user_data);
2083 }
2084
2085 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
2086                                 pkgmgrinfo_app_list_cb app_cb, void * user_data)
2087 {
2088         return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
2089 }
2090
2091 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
2092 {
2093         return (pkgmgrinfo_pkginfo_filter_create(handle));
2094 }
2095
2096 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
2097 {
2098         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2099 }
2100
2101 API int pkgmgrinfo_appinfo_metadata_filter_add(
2102                 pkgmgrinfo_appinfo_metadata_filter_h handle,
2103                 const char *key, const char *value)
2104 {
2105         int ret;
2106
2107         ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2108                         PMINFO_APPINFO_PROP_APP_METADATA_KEY, key);
2109         if (ret != PMINFO_R_OK)
2110                 return ret;
2111
2112         /* value can be NULL.
2113          * In that case all apps with specified key should be displayed
2114          */
2115         if (value) {
2116                 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2117                                 PMINFO_APPINFO_PROP_APP_METADATA_VALUE, value);
2118                 if (ret != PMINFO_R_OK)
2119                         return ret;
2120         }
2121
2122         return PMINFO_R_OK;
2123 }
2124
2125 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2126                 pkgmgrinfo_appinfo_metadata_filter_h handle,
2127                 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2128 {
2129         if (handle == NULL || app_cb == NULL) {
2130                 LOGE("invalid parameter");
2131                 return PMINFO_R_EINVAL;
2132         }
2133
2134         return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2135                         user_data);
2136 }
2137
2138 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
2139                 pkgmgrinfo_appinfo_metadata_filter_h handle,
2140                 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2141 {
2142         return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
2143                         user_data, GLOBAL_USER);
2144 }
2145
2146 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2147 {
2148         const char *val;
2149         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2150
2151         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2152         retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2153
2154         val = info->app_info->guestmode_visibility;
2155         *status = _get_bool_value(val);
2156         return PMINFO_R_OK;
2157 }