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