remove not-used attribute (name of icon & image & preload-removable)
[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 GList *__get_background_category(char *value)
507 {
508         GList *category_list = NULL;
509         int convert_value = 0;
510         if (!value || strlen(value) == 0)
511                 return NULL;
512
513         convert_value = atoi(value);
514         if (convert_value < 0)
515                 return NULL;
516
517         if (convert_value & APP_BG_CATEGORY_USER_DISABLE_TRUE_VAL)
518                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_TRUE_STR));
519         else
520                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_FALSE_STR));
521
522         if (convert_value & APP_BG_CATEGORY_MEDIA_VAL)
523                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_MEDIA_STR));
524
525         if (convert_value & APP_BG_CATEGORY_DOWNLOAD_VAL)
526                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_DOWNLOAD_STR));
527
528         if (convert_value & APP_BG_CATEGORY_BGNETWORK_VAL)
529                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_BGNETWORK_STR));
530
531         if (convert_value & APP_BG_CATEGORY_LOCATION_VAL)
532                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_LOCATION_STR));
533
534         if (convert_value & APP_BG_CATEGORY_SENSOR_VAL)
535                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SENSOR_STR));
536
537         if (convert_value & APP_BG_CATEGORY_IOTCOMM_VAL)
538                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_IOTCOMM_STR));
539
540         if (convert_value & APP_BG_CATEGORY_SYSTEM_VAL)
541                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SYSTEM));
542
543         return category_list;
544
545 }
546
547 static int _appinfo_get_application(sqlite3 *db, const char *appid,
548                 const char *locale, application_x **application)
549 {
550         static const char query_raw[] =
551                 "SELECT app_id, app_component, app_exec, app_nodisplay, "
552                 "app_type, app_onboot, app_multiple, app_autorestart, "
553                 "app_taskmanage, app_enabled, app_hwacceleration, "
554                 "app_screenreader, app_mainapp, app_recentimage, "
555                 "app_launchcondition, app_indicatordisplay, app_portraitimg, "
556                 "app_landscapeimg, app_guestmodevisibility, "
557                 "app_permissiontype, app_preload, app_submode, "
558                 "app_submode_mainid, app_launch_mode, app_ui_gadget, "
559                 "app_support_disable, "
560                 "component_type, package, app_process_pool, app_installed_storage, "
561                 "app_background_category, app_package_type "
562                 "FROM package_app_info WHERE app_id='%s' "
563                 "AND app_id NOT IN "
564                 "(SELECT app_id from package_app_disable_for_user WHERE uid='%d')";
565         int ret;
566         char query[MAX_QUERY_LEN] = { '\0' };
567         sqlite3_stmt *stmt;
568         int idx;
569         application_x *info;
570         char *bg_category_str = NULL;
571         snprintf(query, MAX_QUERY_LEN - 1, query_raw, appid, (int)getuid());
572         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
573         if (ret != SQLITE_OK) {
574                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
575                 return PMINFO_R_ERROR;
576         }
577
578         ret = sqlite3_step(stmt);
579         if (ret == SQLITE_DONE) {
580                 sqlite3_finalize(stmt);
581                 return PMINFO_R_ENOENT;
582         } else if (ret != SQLITE_ROW) {
583                 LOGE("step failed: %s", sqlite3_errmsg(db));
584                 sqlite3_finalize(stmt);
585                 return PMINFO_R_ERROR;
586         }
587
588         info = calloc(1, sizeof(application_x));
589         if (info == NULL) {
590                 LOGE("out of memory");
591                 sqlite3_finalize(stmt);
592                 return PMINFO_R_ERROR;
593         }
594         idx = 0;
595         _save_column_str(stmt, idx++, &info->appid);
596         _save_column_str(stmt, idx++, &info->component);
597         _save_column_str(stmt, idx++, &info->exec);
598         _save_column_str(stmt, idx++, &info->nodisplay);
599         _save_column_str(stmt, idx++, &info->type);
600         _save_column_str(stmt, idx++, &info->onboot);
601         _save_column_str(stmt, idx++, &info->multiple);
602         _save_column_str(stmt, idx++, &info->autorestart);
603         _save_column_str(stmt, idx++, &info->taskmanage);
604         _save_column_str(stmt, idx++, &info->enabled);
605         _save_column_str(stmt, idx++, &info->hwacceleration);
606         _save_column_str(stmt, idx++, &info->screenreader);
607         _save_column_str(stmt, idx++, &info->mainapp);
608         _save_column_str(stmt, idx++, &info->recentimage);
609         _save_column_str(stmt, idx++, &info->launchcondition);
610         _save_column_str(stmt, idx++, &info->indicatordisplay);
611         _save_column_str(stmt, idx++, &info->portraitimg);
612         _save_column_str(stmt, idx++, &info->landscapeimg);
613         _save_column_str(stmt, idx++, &info->guestmode_visibility);
614         _save_column_str(stmt, idx++, &info->permission_type);
615         _save_column_str(stmt, idx++, &info->preload);
616         _save_column_str(stmt, idx++, &info->submode);
617         _save_column_str(stmt, idx++, &info->submode_mainid);
618         _save_column_str(stmt, idx++, &info->launch_mode);
619         _save_column_str(stmt, idx++, &info->ui_gadget);
620         _save_column_str(stmt, idx++, &info->support_disable);
621         _save_column_str(stmt, idx++, &info->component_type);
622         _save_column_str(stmt, idx++, &info->package);
623         _save_column_str(stmt, idx++, &info->process_pool);
624         _save_column_str(stmt, idx++, &info->installed_storage);
625         _save_column_str(stmt, idx++, &bg_category_str);
626         _save_column_str(stmt, idx++, &info->package_type);
627
628         info->background_category = __get_background_category(bg_category_str);
629
630         if (_appinfo_get_label(db, info->appid, locale, &info->label)) {
631                 pkgmgrinfo_basic_free_application(info);
632                 sqlite3_finalize(stmt);
633                 return PMINFO_R_ERROR;
634         }
635
636         if (_appinfo_get_icon(db, info->appid, locale, &info->icon)) {
637                 pkgmgrinfo_basic_free_application(info);
638                 sqlite3_finalize(stmt);
639                 return PMINFO_R_ERROR;
640         }
641
642         if (_appinfo_get_category(db, info->appid, &info->category)) {
643                 pkgmgrinfo_basic_free_application(info);
644                 sqlite3_finalize(stmt);
645                 return PMINFO_R_ERROR;
646         }
647
648         if (_appinfo_get_app_control(db, info->appid, &info->appcontrol)) {
649                 pkgmgrinfo_basic_free_application(info);
650                 sqlite3_finalize(stmt);
651                 return PMINFO_R_ERROR;
652         }
653
654         if (_appinfo_get_data_control(db, info->appid, &info->datacontrol)) {
655                 pkgmgrinfo_basic_free_application(info);
656                 sqlite3_finalize(stmt);
657                 return PMINFO_R_ERROR;
658         }
659
660         if (_appinfo_get_metadata(db, info->appid, &info->metadata)) {
661                 pkgmgrinfo_basic_free_application(info);
662                 sqlite3_finalize(stmt);
663                 return PMINFO_R_ERROR;
664         }
665
666         *application = info;
667
668         sqlite3_finalize(stmt);
669
670         return PMINFO_R_OK;
671 }
672
673 static int _appinfo_get_appinfo(const char *appid, uid_t uid,
674                 pkgmgr_appinfo_x **appinfo)
675 {
676         int ret;
677         sqlite3 *db;
678         const char *dbpath;
679         char *locale;
680         pkgmgr_appinfo_x *info;
681
682         dbpath = getUserPkgParserDBPathUID(uid);
683         if (dbpath == NULL)
684                 return PMINFO_R_ERROR;
685
686         locale = _get_system_locale();
687         if (locale == NULL)
688                 return PMINFO_R_ERROR;
689
690         ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
691         if (ret != SQLITE_OK) {
692                 _LOGE("failed to open db: %d", ret);
693                 free(locale);
694                 return PMINFO_R_ERROR;
695         }
696
697         info = calloc(1, sizeof(pkgmgr_appinfo_x));
698         if (info == NULL) {
699                 _LOGE("out of memory");
700                 free(locale);
701                 sqlite3_close_v2(db);
702                 return PMINFO_R_ERROR;
703         }
704
705         ret = _appinfo_get_application(db, appid, locale, &info->app_info);
706         if (ret != PMINFO_R_OK) {
707                 free(info);
708                 free(locale);
709                 sqlite3_close_v2(db);
710                 return ret;
711         }
712
713         info->locale = locale;
714         info->package = strdup(info->app_info->package);
715
716         *appinfo = info;
717
718         sqlite3_close_v2(db);
719
720         return ret;
721 }
722
723 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
724                 pkgmgrinfo_appinfo_h *handle)
725 {
726         int ret;
727
728         if (appid == NULL || handle == NULL) {
729                 LOGE("invalid parameter");
730                 return PMINFO_R_EINVAL;
731         }
732
733         ret = _appinfo_get_appinfo(appid, uid, (pkgmgr_appinfo_x **)handle);
734         if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
735                 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
736                                 (pkgmgr_appinfo_x **)handle);
737
738         if (ret != PMINFO_R_OK)
739                 _LOGE("failed to get appinfo of %s for user %d", appid, uid);
740
741         return ret;
742 }
743
744 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
745 {
746         return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
747 }
748
749 static gpointer __copy_str(gconstpointer src, gpointer data)
750 {
751         const char *tmp = (const char *)src;
752         const char *buffer;
753
754         buffer = strdup(tmp);
755         if (buffer == NULL) {
756                 LOGE("memory alloc failed");
757                 *(int *)data = -1;
758                 return NULL;
759         }
760
761         return buffer;
762 }
763
764 static gpointer __copy_label(gconstpointer src, gpointer data)
765 {
766         label_x *tmp = (label_x *)src;
767         label_x *label;
768
769         label = calloc(1, sizeof(label_x));
770         if (label == NULL) {
771                 LOGE("memory alloc failed");
772                 *(int *)data = -1;
773                 return NULL;
774         }
775
776         if (tmp->name)
777                 label->name = strdup(tmp->name);
778         if (tmp->text)
779                 label->text = strdup(tmp->text);
780         if (tmp->lang)
781                 label->lang = strdup(tmp->lang);
782
783         return label;
784 }
785
786 static gpointer __copy_icon(gconstpointer src, gpointer data)
787 {
788         icon_x *tmp = (icon_x *)src;
789         icon_x *icon;
790
791         icon = calloc(1, sizeof(icon_x));
792         if (icon== NULL) {
793                 LOGE("memory alloc failed");
794                 *(int *)data = -1;
795                 return NULL;
796         }
797
798         if (tmp->text)
799                 icon->text = strdup(tmp->text);
800         if (tmp->lang)
801                 icon->lang = strdup(tmp->lang);
802         if (tmp->section)
803                 icon->section = strdup(tmp->section);
804         if (tmp->size)
805                 icon->size = strdup(tmp->size);
806         if (tmp->resolution)
807                 icon->resolution = strdup(tmp->resolution);
808
809         return icon;
810 }
811
812 static gpointer __copy_metadata(gconstpointer src, gpointer data)
813 {
814         metadata_x *tmp = (metadata_x *)src;
815         metadata_x *metadata;
816
817         metadata = calloc(1, sizeof(metadata_x));
818         if (metadata == NULL) {
819                 LOGE("memory alloc failed");
820                 *(int *)data = -1;
821                 return NULL;
822         }
823
824         if (tmp->key)
825                 metadata->key = strdup(tmp->key);
826         if (tmp->value)
827                 metadata->value = strdup(tmp->value);
828
829         return metadata;
830 }
831
832 static gpointer __copy_datacontrol(gconstpointer src, gpointer data)
833 {
834         datacontrol_x *tmp = (datacontrol_x *)src;
835         datacontrol_x *datacontrol;
836
837         datacontrol = calloc(1, sizeof(datacontrol_x));
838         if (datacontrol == NULL) {
839                 LOGE("memory alloc failed");
840                 *(int *)data = -1;
841                 return NULL;
842         }
843
844         if (tmp->providerid)
845                 datacontrol->providerid = strdup(tmp->providerid);
846         if (tmp->access)
847                 datacontrol->access = strdup(tmp->access);
848         if (tmp->type)
849                 datacontrol->type = strdup(tmp->type);
850
851         return datacontrol;
852 }
853
854 static gpointer __copy_appcontrol(gconstpointer src, gpointer data)
855 {
856         appcontrol_x *tmp = (appcontrol_x *)src;
857         appcontrol_x *appcontrol;
858
859         appcontrol = calloc(1, sizeof(appcontrol_x));
860         if (appcontrol ==NULL) {
861                 LOGE("memory alloc failed");
862                 *(int *)data = -1;
863                 return NULL;
864         }
865
866         if (tmp->operation)
867                 appcontrol->operation = strdup(tmp->operation);
868         if (tmp->uri)
869                 appcontrol->uri = strdup(tmp->uri);
870         if (tmp->mime)
871                 appcontrol->mime = strdup(tmp->mime);
872
873         return appcontrol;
874 }
875
876 static int _appinfo_copy_appinfo(application_x **application, application_x *data)
877 {
878         application_x *app_info;
879         int ret;
880
881         app_info = calloc(1, sizeof(application_x));
882         if (app_info == NULL) {
883                 LOGE("memory alloc failed");
884                 return PMINFO_R_ERROR;
885         }
886
887         if (data->appid != NULL)
888                 app_info->appid = strdup(data->appid);
889         if (data->exec != NULL)
890                 app_info->exec = strdup(data->exec);
891         if (data->nodisplay != NULL)
892                 app_info->nodisplay = strdup(data->nodisplay);
893         if (data->multiple != NULL)
894                 app_info->multiple = strdup(data->multiple);
895         if (data->taskmanage != NULL)
896                 app_info->taskmanage = strdup(data->taskmanage);
897         if (data->enabled != NULL)
898                 app_info->enabled = strdup(data->enabled);
899         if (data->type != NULL)
900                 app_info->type = strdup(data->type);
901         if (data->categories != NULL)
902                 app_info->categories = strdup(data->categories);
903         if (data->hwacceleration != NULL)
904                 app_info->hwacceleration = strdup(data->hwacceleration);
905         if (data->screenreader != NULL)
906                 app_info->screenreader = strdup(data->screenreader);
907         if (data->mainapp != NULL)
908                 app_info->mainapp = strdup(data->mainapp);
909         if (data->package != NULL)
910                 app_info->package = strdup(data->package);
911         if (data->recentimage != NULL)
912                 app_info->recentimage = strdup(data->recentimage);
913         if (data->launchcondition != NULL)
914                 app_info->launchcondition = strdup(data->launchcondition);
915         if (data->indicatordisplay != NULL)
916                 app_info->indicatordisplay = strdup(data->indicatordisplay);
917         if (data->portraitimg != NULL)
918                 app_info->portraitimg = strdup(data->portraitimg);
919         if (data->landscapeimg != NULL)
920                 app_info->landscapeimg = strdup(data->landscapeimg);
921         if (data->guestmode_visibility != NULL)
922                 app_info->guestmode_visibility = strdup(data->guestmode_visibility);
923         if (data->component != NULL)
924                 app_info->component = strdup(data->component);
925         if (data->permission_type != NULL)
926                 app_info->permission_type = strdup(data->permission_type);
927         if (data->component_type != NULL)
928                 app_info->component_type = strdup(data->component_type);
929         if (data->preload != NULL)
930                 app_info->preload = strdup(data->preload);
931         if (data->submode != NULL)
932                 app_info->submode = strdup(data->submode);
933         if (data->submode_mainid != NULL)
934                 app_info->submode_mainid = strdup(data->submode_mainid);
935         if (data->process_pool != NULL)
936                 app_info->process_pool = strdup(data->process_pool);
937         if (data->installed_storage != NULL)
938                 app_info->installed_storage = strdup(data->installed_storage);
939         if (data->autorestart != NULL)
940                 app_info->autorestart = strdup(data->autorestart);
941         if (data->onboot != NULL)
942                 app_info->onboot = strdup(data->onboot);
943         if (data->support_disable != NULL)
944                 app_info->support_disable = strdup(data->support_disable);
945         if (data->ui_gadget != NULL)
946                 app_info->ui_gadget = strdup(data->ui_gadget);
947         if (data->launch_mode != NULL)
948                 app_info->launch_mode = strdup(data->launch_mode);
949         if (data->package_type != NULL)
950                 app_info->package_type = strdup(data->package_type);
951
952         /* GList */
953         ret = 0;
954         app_info->label = g_list_copy_deep(data->label, __copy_label, &ret);
955         if (ret < 0) {
956                 LOGE("memory alloc failed");
957                 pkgmgrinfo_basic_free_application(app_info);
958                 return PMINFO_R_ERROR;
959         }
960
961         ret = 0;
962         app_info->icon = g_list_copy_deep(data->icon, __copy_icon, &ret);
963         if (ret < 0) {
964                 LOGE("memory alloc failed");
965                 pkgmgrinfo_basic_free_application(app_info);
966                 return PMINFO_R_ERROR;
967         }
968
969         ret = 0;
970         app_info->category = g_list_copy_deep(data->category, __copy_str, &ret);
971         if (ret < 0) {
972                 LOGE("memory alloc failed");
973                 pkgmgrinfo_basic_free_application(app_info);
974                 return PMINFO_R_ERROR;
975         }
976
977         ret = 0;
978         app_info->metadata = g_list_copy_deep(data->metadata, __copy_metadata, &ret);
979         if (ret < 0) {
980                 LOGE("memory alloc failed");
981                 pkgmgrinfo_basic_free_application(app_info);
982                 return PMINFO_R_ERROR;
983         }
984
985         ret = 0;
986         app_info->datacontrol = g_list_copy_deep(data->datacontrol, __copy_datacontrol, &ret);
987         if (ret < 0) {
988                 LOGE("memory alloc failed");
989                 pkgmgrinfo_basic_free_application(app_info);
990                 return PMINFO_R_ERROR;
991         }
992
993         ret = 0;
994         app_info->appcontrol = g_list_copy_deep(data->appcontrol, __copy_appcontrol, &ret);
995         if (ret < 0) {
996                 LOGE("memory alloc failed");
997                 pkgmgrinfo_basic_free_application(app_info);
998                 return PMINFO_R_ERROR;
999         }
1000
1001         ret = 0;
1002         app_info->background_category = g_list_copy_deep(data->background_category, __copy_str, &ret);
1003         if (ret < 0) {
1004                 LOGE("memory alloc failed");
1005                 pkgmgrinfo_basic_free_application(app_info);
1006                 return PMINFO_R_ERROR;
1007         }
1008
1009         *application = app_info;
1010
1011         return PMINFO_R_OK;
1012 }
1013
1014 API int pkgmgrinfo_appinfo_clone_appinfo(pkgmgrinfo_appinfo_h handle,
1015                 pkgmgrinfo_appinfo_h *clone)
1016 {
1017         pkgmgr_appinfo_x *info;
1018         pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle;
1019
1020         if (handle == NULL)
1021                 return PMINFO_R_EINVAL;
1022
1023         info = calloc(1, sizeof(pkgmgr_appinfo_x));
1024         if (info == NULL) {
1025                 LOGE("memory alloc failed");
1026                 return PMINFO_R_ERROR;
1027         }
1028
1029         if (temp->package != NULL)
1030                 info->package = strdup(temp->package);
1031         if (temp->locale != NULL)
1032                 info->locale = strdup(temp->locale);
1033
1034         info->app_component = temp->app_component;
1035
1036         if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) {
1037                 LOGE("appinfo copy failed");
1038                 if (info->package)
1039                         free((void *)info->package);
1040                 if (info->locale)
1041                         free(info->locale);
1042                 free(info);
1043                 return PMINFO_R_ERROR;
1044         }
1045
1046         *clone = info;
1047
1048         return PMINFO_R_OK;
1049 }
1050
1051 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
1052                 pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb,
1053                 void *user_data)
1054 {
1055         int ret;
1056         pkgmgr_appinfo_x *info;
1057         GList *list = NULL;
1058         GList *tmp;
1059         char *appid;
1060         int stop = 0;
1061
1062         ret = _appinfo_get_filtered_list(filter, uid, &list);
1063         if (ret != PMINFO_R_OK)
1064                 return PMINFO_R_ERROR;
1065
1066         for (tmp = list; tmp; tmp = tmp->next) {
1067                 appid = (char *)tmp->data;
1068                 if (stop == 0) {
1069                         ret = _appinfo_get_appinfo(appid, uid, &info);
1070                         if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
1071                                 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
1072                                                 &info);
1073                         if (ret != PMINFO_R_OK) {
1074                                 free(appid);
1075                                 continue;
1076                         }
1077                         if (app_list_cb(info, user_data) < 0)
1078                                 stop = 1;
1079                         pkgmgrinfo_appinfo_destroy_appinfo(info);
1080                 }
1081                 free(appid);
1082         }
1083
1084         g_list_free(list);
1085
1086         return PMINFO_R_OK;
1087 }
1088
1089 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
1090                 pkgmgrinfo_app_component component,
1091                 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
1092 {
1093         int ret;
1094         pkgmgrinfo_appinfo_filter_h filter;
1095         char *pkgid;
1096         const char *comp_str = NULL;
1097
1098         if (handle == NULL || app_func == NULL) {
1099                 LOGE("invalid parameter");
1100                 return PMINFO_R_EINVAL;
1101         }
1102
1103         if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
1104                 LOGE("invalid parameter");
1105                 return PMINFO_R_EINVAL;
1106         }
1107
1108         if (pkgmgrinfo_appinfo_filter_create(&filter))
1109                 return PMINFO_R_ERROR;
1110
1111         if (pkgmgrinfo_appinfo_filter_add_string(filter,
1112                                 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
1113                 pkgmgrinfo_appinfo_filter_destroy(filter);
1114                 return PMINFO_R_ERROR;
1115         }
1116
1117         if (uid == GLOBAL_USER) {
1118                 if (pkgmgrinfo_appinfo_filter_add_int(filter,
1119                                         PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER, (int)getuid())) {
1120                         pkgmgrinfo_appinfo_filter_destroy(filter);
1121                         return PMINFO_R_ERROR;
1122                 }
1123         }
1124
1125         switch (component) {
1126         case PMINFO_UI_APP:
1127                 comp_str = PMINFO_APPINFO_UI_APP;
1128                 break;
1129         case PMINFO_SVC_APP:
1130                 comp_str = PMINFO_APPINFO_SVC_APP;
1131                 break;
1132         default:
1133                 break;
1134         }
1135
1136         if (comp_str) {
1137                 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1138                                         PMINFO_APPINFO_PROP_APP_COMPONENT,
1139                                         comp_str)) {
1140                         pkgmgrinfo_appinfo_filter_destroy(filter);
1141                         return PMINFO_R_ERROR;
1142                 }
1143         }
1144
1145         ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, app_func,
1146                         user_data);
1147
1148         pkgmgrinfo_appinfo_filter_destroy(filter);
1149
1150         return ret;
1151 }
1152
1153 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
1154                                                 pkgmgrinfo_app_list_cb app_func, void *user_data)
1155 {
1156         return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
1157 }
1158
1159 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1160 {
1161         if (app_func == NULL) {
1162                 LOGE("invalid parameter");
1163                 return PMINFO_R_EINVAL;
1164         }
1165
1166         return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
1167                         user_data);
1168 }
1169
1170 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
1171 {
1172         return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
1173 }
1174
1175 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1176 {
1177         if (app_func == NULL) {
1178                 LOGE("invalid parameter");
1179                 return PMINFO_R_EINVAL;
1180         }
1181
1182         return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
1183                         user_data);
1184 }
1185
1186 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
1187 {
1188         return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
1189 }
1190
1191 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
1192 {
1193         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1194
1195         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1196         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1197
1198         if (info->app_info == NULL || info->app_info->appid == NULL)
1199                 return PMINFO_R_ERROR;
1200         *appid = (char *)info->app_info->appid;
1201
1202         return PMINFO_R_OK;
1203 }
1204
1205 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
1206 {
1207         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1208
1209         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1210         retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1211
1212         if (info->package == NULL)
1213                 return PMINFO_R_ERROR;
1214
1215         *pkg_name = (char *)info->package;
1216
1217         return PMINFO_R_OK;
1218 }
1219
1220 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
1221 {
1222         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1223
1224         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1225         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1226
1227         if (info->package == NULL)
1228                 return PMINFO_R_ERROR;
1229
1230         *pkgid = (char *)info->package;
1231
1232         return PMINFO_R_OK;
1233 }
1234
1235 API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h  handle, char **pkgtype)
1236 {
1237         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1238         retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1239         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1240
1241         *pkgtype = (char *)info->app_info->package_type;
1242
1243         return PMINFO_R_OK;
1244 }
1245
1246 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
1247 {
1248         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1249
1250         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1251         retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1252
1253         if (info->app_info == NULL || info->app_info->exec == NULL)
1254                 return PMINFO_R_ERROR;
1255         *exec = (char *)info->app_info->exec;
1256
1257         return PMINFO_R_OK;
1258 }
1259
1260
1261 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1262 {
1263         const char *locale;
1264         icon_x *ptr;
1265         GList *tmp;
1266         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1267
1268         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1269         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1270
1271         locale = info->locale;
1272         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1273
1274         if (info->app_info == NULL)
1275                 return PMINFO_R_ERROR;
1276
1277         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1278                 ptr = (icon_x *)tmp->data;
1279                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1280                                 !strcasecmp(ptr->text, "") ||
1281                                 strcmp(ptr->lang, locale))
1282                         continue;
1283                 *icon = (char *)ptr->text;
1284                 return PMINFO_R_OK;
1285         }
1286
1287         locale = DEFAULT_LOCALE;
1288         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1289                 ptr = (icon_x *)tmp->data;
1290                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1291                                 strcmp(ptr->lang, locale))
1292                         continue;
1293                 *icon = (char *)ptr->text;
1294                 return PMINFO_R_OK;
1295         }
1296
1297         return PMINFO_R_ERROR;
1298 }
1299
1300
1301 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
1302 {
1303         const char *locale;
1304         label_x *ptr;
1305         GList *tmp;
1306         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1307
1308         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1309         retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1310
1311         locale = info->locale;
1312         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1313
1314         if (info->app_info == NULL)
1315                 return PMINFO_R_ERROR;
1316
1317         for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1318                 ptr = (label_x *)tmp->data;
1319                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1320                                 strcmp(ptr->lang, locale))
1321                         continue;
1322                 *label = (char *)ptr->text;
1323                 return PMINFO_R_OK;
1324         }
1325
1326         locale = DEFAULT_LOCALE;
1327         for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1328                 ptr = (label_x *)tmp->data;
1329                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1330                                 strcmp(ptr->lang, locale))
1331                         continue;
1332                 *label = (char *)ptr->text;
1333                 return PMINFO_R_OK;
1334         }
1335
1336         return PMINFO_R_ERROR;
1337 }
1338
1339 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1340 {
1341         char *result = NULL;
1342         char *query = NULL;
1343         sqlite3_stmt *stmt = NULL;
1344         sqlite3 *db = NULL;
1345         char *val;
1346         const char *manifest_db;
1347
1348         manifest_db = getUserPkgParserDBPathUID(uid);
1349         if (manifest_db == NULL) {
1350                 _LOGE("Failed to get manifest db path");
1351                 goto err;
1352         }
1353
1354         if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
1355                 _LOGE("DB open fail\n");
1356                 goto err;
1357         }
1358
1359         query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1360         if (query == NULL) {
1361                 _LOGE("Out of memory");
1362                 goto err;
1363         }
1364
1365         if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1366                 _LOGE("prepare_v2 fail\n");
1367                 goto err;
1368         }
1369
1370         if (sqlite3_step(stmt) == SQLITE_ROW) {
1371                 val = (char *)sqlite3_column_text(stmt, 0);
1372                 if (val != NULL)
1373                         result = strdup(val);
1374         }
1375
1376 err:
1377         sqlite3_finalize(stmt);
1378         sqlite3_free(query);
1379         sqlite3_close(db);
1380
1381         return result;
1382 }
1383
1384 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1385 {
1386         char *val;
1387
1388         retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1389
1390         val = _get_localed_label(appid, locale, uid);
1391         if (val == NULL)
1392                 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1393
1394         if (val == NULL)
1395                 return PMINFO_R_ERROR;
1396
1397         *label = val;
1398
1399         return PMINFO_R_OK;
1400 }
1401
1402 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1403 {
1404         return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
1405 }
1406
1407 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1408 {
1409         if ( strcasecmp(comp, "uiapp") == 0)
1410                 return PMINFO_UI_APP;
1411         else if ( strcasecmp(comp, "svcapp") == 0)
1412                 return PMINFO_SVC_APP;
1413         else
1414                 return -1;
1415 }
1416
1417 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1418 {
1419         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1420         int comp;
1421
1422         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1423         retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1424
1425         if (info->app_info == NULL)
1426                 return PMINFO_R_ERROR;
1427
1428         comp = __appcomponent_convert(info->app_info->component);
1429         if (comp < 0)
1430                 return PMINFO_R_ERROR;
1431
1432         *component = comp;
1433
1434         return PMINFO_R_OK;
1435 }
1436
1437 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1438 {
1439         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1440
1441         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1442         retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1443
1444         if (info->app_info == NULL || info->app_info->type == NULL)
1445                 return PMINFO_R_ERROR;
1446         *app_type = (char *)info->app_info->type;
1447
1448         return PMINFO_R_OK;
1449 }
1450
1451 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h  handle,
1452                                         int *operation_count, char ***operation)
1453 {
1454         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1455         retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1456         retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1457         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1458         *operation_count = data->operation_count;
1459         *operation = data->operation;
1460         return PMINFO_R_OK;
1461 }
1462
1463 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h  handle,
1464                                         int *uri_count, char ***uri)
1465 {
1466         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1467         retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1468         retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1469         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1470         *uri_count = data->uri_count;
1471         *uri = data->uri;
1472         return PMINFO_R_OK;
1473 }
1474
1475 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h  handle,
1476                                         int *mime_count, char ***mime)
1477 {
1478         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1479         retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1480         retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1481         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1482         *mime_count = data->mime_count;
1483         *mime = data->mime;
1484         return PMINFO_R_OK;
1485 }
1486
1487 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h  handle,
1488                                         int *subapp_count, char ***subapp)
1489 {
1490         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1491         retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1492         retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1493         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1494         *subapp_count = data->subapp_count;
1495         *subapp = data->subapp;
1496         return PMINFO_R_OK;
1497 }
1498
1499 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1500 {
1501         char *val;
1502         icon_x *ptr;
1503         GList *tmp;
1504         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1505
1506         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1507         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1508
1509         if (info->app_info == NULL)
1510                 return PMINFO_R_ERROR;
1511
1512         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1513                 ptr = (icon_x *)tmp->data;
1514                 if (ptr == NULL || ptr->section == NULL)
1515                         continue;
1516
1517                 val = (char *)ptr->section;
1518                 if (val && strcmp(val, "setting") == 0) {
1519                         *icon = (char *)ptr->text;
1520                         return PMINFO_R_OK;
1521                 }
1522         }
1523
1524         return PMINFO_R_ERROR;
1525 }
1526
1527
1528 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1529 {
1530         char *val;
1531         icon_x *ptr;
1532         GList *tmp;
1533         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1534
1535         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1536         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1537
1538         if (info->app_info == NULL)
1539                 return PMINFO_R_ERROR;
1540
1541         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1542                 ptr = (icon_x *)tmp->data;
1543                 if (ptr == NULL || ptr->section == NULL)
1544                         continue;
1545
1546                 val = (char *)ptr->section;
1547                 if (val && strcmp(val, "notification") == 0){
1548                         *icon = (char *)ptr->text;
1549                         return PMINFO_R_OK;
1550                 }
1551         }
1552
1553         return PMINFO_R_ERROR;
1554 }
1555
1556 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1557 {
1558         char *val;
1559         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1560
1561         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1562         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1563
1564         if (info->app_info == NULL || info->app_info->recentimage == NULL)
1565                 return PMINFO_R_ERROR;
1566
1567         val = (char *)info->app_info->recentimage;
1568         if (strcasecmp(val, "capture") == 0)
1569                 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1570         else if (strcasecmp(val, "icon") == 0)
1571                 *type = PMINFO_RECENTIMAGE_USE_ICON;
1572         else
1573                 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1574
1575         return PMINFO_R_OK;
1576 }
1577
1578 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1579 {
1580         char *val;
1581         image_x *ptr;
1582         GList *tmp;
1583         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1584
1585         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1586         retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1587
1588         if (info->app_info == NULL)
1589                 return PMINFO_R_ERROR;
1590
1591         for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1592                 ptr = (image_x *)tmp->data;
1593                 if (ptr == NULL || ptr->section == NULL)
1594                         continue;
1595
1596                 val = (char *)ptr->section;
1597                 if (val && strcmp(val, "preview") == 0) {
1598                         *preview_img = (char *)ptr->text;
1599                         return PMINFO_R_OK;
1600                 }
1601         }
1602
1603         return PMINFO_R_ERROR;
1604 }
1605
1606 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1607 {
1608         const char *val;
1609         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1610
1611         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1612         retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1613
1614         val = info->app_info->permission_type;
1615         if (val == NULL)
1616                 return PMINFO_R_ERROR;
1617
1618         if (strcmp(val, "signature") == 0)
1619                 *permission = PMINFO_PERMISSION_SIGNATURE;
1620         else if (strcmp(val, "privilege") == 0)
1621                 *permission = PMINFO_PERMISSION_PRIVILEGE;
1622         else
1623                 *permission = PMINFO_PERMISSION_NORMAL;
1624
1625         return PMINFO_R_OK;
1626 }
1627
1628 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1629 {
1630         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1631
1632         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1633         retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1634
1635         if (info->app_info == NULL || info->app_info->component_type == NULL)
1636                 return PMINFO_R_ERROR;
1637
1638         *component_type = (char *)info->app_info->component_type;
1639
1640         return PMINFO_R_OK;
1641 }
1642
1643 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1644 {
1645         char *val;
1646         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1647
1648         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1649         retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1650
1651         if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1652                 return PMINFO_R_ERROR;
1653
1654         val = (char *)info->app_info->hwacceleration;
1655         if (strcasecmp(val, "not-use-GL") == 0)
1656                 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
1657         else if (strcasecmp(val, "use-GL") == 0)
1658                 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
1659         else
1660                 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
1661
1662         return PMINFO_R_OK;
1663 }
1664
1665 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1666 {
1667         char *val;
1668         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1669
1670         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1671         retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1672
1673         if (info->app_info == NULL || info->app_info->screenreader == NULL)
1674                 return PMINFO_R_ERROR;
1675
1676         val = (char *)info->app_info->screenreader;
1677         if (strcasecmp(val, "screenreader-off") == 0)
1678                 *screenreader = PMINFO_SCREENREADER_OFF;
1679         else if (strcasecmp(val, "screenreader-on") == 0)
1680                 *screenreader = PMINFO_SCREENREADER_ON;
1681         else
1682                 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1683
1684         return PMINFO_R_OK;
1685 }
1686
1687 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1688 {
1689         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1690
1691         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1692         retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1693         retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1694
1695         if (info->app_info == NULL || (info->app_info->portraitimg == NULL
1696                         && info->app_info->landscapeimg == NULL))
1697                 return PMINFO_R_ERROR;
1698
1699         *portrait_img = (char *)info->app_info->portraitimg;
1700         *landscape_img = (char *)info->app_info->landscapeimg;
1701
1702         return PMINFO_R_OK;
1703 }
1704
1705 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
1706 {
1707         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1708
1709         if (handle == NULL || effectimage_type == NULL) {
1710                 LOGE("invalid parameter");
1711                 return PMINFO_R_EINVAL;
1712         }
1713
1714         if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
1715                 return PMINFO_R_ERROR;
1716
1717         *effectimage_type = (char *)info->app_info->effectimage_type;
1718
1719         return PMINFO_R_OK;
1720 }
1721
1722 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h  handle, char **submode_mainid)
1723 {
1724         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1725
1726         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1727         retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1728
1729         if (info->app_info == NULL || info->app_info->submode_mainid == NULL)
1730                 return PMINFO_R_ERROR;
1731
1732         *submode_mainid = (char *)info->app_info->submode_mainid;
1733
1734         return PMINFO_R_OK;
1735 }
1736
1737 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
1738 {
1739         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1740         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1741
1742         if (info->app_info && info->app_info->installed_storage){
1743                  if (strcmp(info->app_info->installed_storage,"installed_internal") == 0)
1744                         *storage = PMINFO_INTERNAL_STORAGE;
1745                  else if (strcmp(info->app_info->installed_storage,"installed_external") == 0)
1746                          *storage = PMINFO_EXTERNAL_STORAGE;
1747                  else
1748                          return PMINFO_R_ERROR;
1749         }else
1750                 return PMINFO_R_ERROR;
1751
1752         return PMINFO_R_OK;
1753 }
1754
1755 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
1756 {
1757         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1758
1759         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1760         retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1761
1762         if (info->app_info->launch_mode == NULL)
1763                 return PMINFO_R_ERROR;
1764
1765         *mode = (char *)(info->app_info->launch_mode);
1766
1767         return PMINFO_R_OK;
1768 }
1769
1770 API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
1771 {
1772         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1773
1774         if (handle == NULL || alias_appid == NULL) {
1775                 LOGE("invalid parameter");
1776                 return PMINFO_R_EINVAL;
1777         }
1778
1779         if (info->app_info == NULL || info->app_info->alias_appid == NULL)
1780                 return PMINFO_R_ERROR;
1781
1782         *alias_appid = (char *)info->app_info->alias_appid;
1783
1784         return PMINFO_R_OK;
1785 }
1786
1787 API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
1788 {
1789         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1790
1791         if (handle == NULL || effective_appid == NULL) {
1792                 LOGE("invalid parameter");
1793                 return PMINFO_R_EINVAL;
1794         }
1795
1796         if (info->app_info == NULL || info->app_info->effective_appid == NULL)
1797                 return PMINFO_R_ERROR;
1798
1799         *effective_appid = (char *)info->app_info->effective_appid;
1800
1801         return PMINFO_R_OK;
1802 }
1803
1804 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
1805 {
1806         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1807         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1808         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1809         retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1810
1811         int ret = PMINFO_R_OK;
1812         char *query = NULL;
1813         sqlite3_stmt *stmt = NULL;
1814
1815         /*open db*/
1816         ret = __open_manifest_db(uid, true);
1817         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1818
1819         /*Start constructing query*/
1820         query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
1821
1822         /*prepare query*/
1823         ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1824         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1825
1826         /*step query*/
1827         ret = sqlite3_step(stmt);
1828         tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1829
1830         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1831         *access = strdup((char *)sqlite3_column_text(stmt, 2));
1832
1833         ret = PMINFO_R_OK;
1834
1835 catch:
1836         sqlite3_free(query);
1837         sqlite3_finalize(stmt);
1838         __close_manifest_db();
1839         return ret;
1840 }
1841
1842 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
1843 {
1844         return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
1845 }
1846
1847 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
1848 {
1849         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1850         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1851
1852         int ret = PMINFO_R_OK;
1853         char *query = NULL;
1854         sqlite3_stmt *stmt = NULL;
1855
1856         /*open db*/
1857         ret = __open_manifest_db(uid, true);
1858         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1859
1860         /*Start constructing query*/
1861         query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
1862
1863         /*prepare query*/
1864         ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1865         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1866
1867         /*step query*/
1868         ret = sqlite3_step(stmt);
1869         tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1870
1871         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1872
1873         ret = PMINFO_R_OK;
1874
1875 catch:
1876         sqlite3_free(query);
1877         sqlite3_finalize(stmt);
1878         __close_manifest_db();
1879         return ret;
1880 }
1881
1882 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1883 {
1884         return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
1885 }
1886
1887 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
1888                         pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
1889 {
1890         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1891         retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1892         int ret = -1;
1893         permission_x *ptr;
1894         GList *tmp;
1895         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1896
1897         if (info->app_info == NULL)
1898                 return PMINFO_R_ERROR;
1899
1900         for (tmp = info->app_info->permission; tmp; tmp = tmp->next) {
1901                 ptr = (permission_x *)tmp->data;
1902                 if (ptr == NULL)
1903                         continue;
1904                 if (ptr->value) {
1905                         ret = permission_func(ptr->value, user_data);
1906                         if (ret < 0)
1907                                 break;
1908                 }
1909         }
1910         return PMINFO_R_OK;
1911 }
1912
1913 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
1914                         pkgmgrinfo_app_category_list_cb category_func, void *user_data)
1915 {
1916         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1917         retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1918         int ret = -1;
1919         const char *category;
1920         GList *tmp;
1921         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1922
1923         if (info->app_info == NULL)
1924                 return PMINFO_R_ERROR;
1925
1926         for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
1927                 category = (const char *)tmp->data;
1928                 if (category) {
1929                         ret = category_func(category, user_data);
1930                         if (ret < 0)
1931                                 break;
1932                 }
1933         }
1934         return PMINFO_R_OK;
1935 }
1936
1937 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
1938                         pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
1939 {
1940         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1941         retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1942         int ret = -1;
1943         metadata_x *ptr;
1944         GList *tmp;
1945         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1946
1947         if (info->app_info == NULL)
1948                 return PMINFO_R_ERROR;
1949
1950         for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
1951                 ptr = (metadata_x *)tmp->data;
1952                 if (ptr == NULL)
1953                         continue;
1954                 if (ptr->key) {
1955                         ret = metadata_func(ptr->key, ptr->value, user_data);
1956                         if (ret < 0)
1957                                 break;
1958                 }
1959         }
1960         return PMINFO_R_OK;
1961 }
1962
1963 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
1964                         pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1965 {
1966         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1967         retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1968         int ret;
1969         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1970         appcontrol_x *appcontrol;
1971         GList *tmp;
1972
1973         if (info->app_info == NULL)
1974                 return PMINFO_R_ERROR;
1975
1976         for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
1977                 appcontrol = (appcontrol_x *)tmp->data;
1978                 if (appcontrol == NULL)
1979                         continue;
1980                 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1981                 if (ret < 0)
1982                         break;
1983         }
1984
1985         return PMINFO_R_OK;
1986 }
1987
1988 API int pkgmgrinfo_appinfo_foreach_background_category(
1989                 pkgmgrinfo_appinfo_h handle,
1990                 pkgmgrinfo_app_background_category_list_cb category_func,
1991                 void *user_data)
1992 {
1993         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1994         GList *tmp;
1995         char *category;
1996
1997         if (handle == NULL || category_func == NULL || info->app_info == NULL) {
1998                 LOGE("invalid parameter");
1999                 return PMINFO_R_EINVAL;
2000         }
2001
2002         for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
2003                 category = (char *)tmp->data;
2004                 if (category == NULL)
2005                         continue;
2006
2007                 if (category_func(category, user_data) < 0)
2008                         break;
2009         }
2010
2011         return PMINFO_R_OK;
2012 }
2013
2014 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
2015 {
2016         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2017         retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2018         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2019
2020         if (info->app_info == NULL || info->app_info->nodisplay == NULL)
2021                 return PMINFO_R_ERROR;
2022
2023         *nodisplay = _get_bool_value(info->app_info->nodisplay);
2024
2025         return PMINFO_R_OK;
2026 }
2027
2028 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
2029 {
2030         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2031         retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2032         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2033
2034         if (info->app_info == NULL || info->app_info->multiple == NULL)
2035                 return PMINFO_R_ERROR;
2036
2037         *multiple = _get_bool_value(info->app_info->multiple);
2038
2039         return PMINFO_R_OK;
2040 }
2041
2042 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
2043 {
2044         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2045         retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2046         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2047
2048         if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
2049                 return PMINFO_R_ERROR;
2050
2051         *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
2052
2053         return PMINFO_R_OK;
2054 }
2055
2056 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h  handle, bool *taskmanage)
2057 {
2058         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2059         retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2060         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2061
2062         if (info->app_info == NULL || info->app_info->taskmanage == NULL)
2063                 return PMINFO_R_ERROR;
2064
2065         *taskmanage = _get_bool_value(info->app_info->taskmanage);
2066
2067         return PMINFO_R_OK;
2068 }
2069
2070 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h  handle, bool *enabled)
2071 {
2072         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2073         retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2074         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2075
2076         if (info->app_info == NULL || info->app_info->enabled == NULL)
2077                 return PMINFO_R_ERROR;
2078
2079         *enabled = _get_bool_value(info->app_info->enabled);
2080
2081         return PMINFO_R_OK;
2082 }
2083
2084 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h  handle, bool *onboot)
2085 {
2086         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2087         retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2088         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2089
2090         if (info->app_info == NULL || info->app_info->onboot == NULL)
2091                 return PMINFO_R_ERROR;
2092
2093         *onboot = _get_bool_value(info->app_info->onboot);
2094
2095         return PMINFO_R_OK;
2096 }
2097
2098 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h  handle, bool *autorestart)
2099 {
2100         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2101         retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2102         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2103
2104         if (info->app_info == NULL || info->app_info->autorestart == NULL)
2105                 return PMINFO_R_ERROR;
2106
2107         *autorestart = _get_bool_value(info->app_info->autorestart);
2108
2109         return PMINFO_R_OK;
2110 }
2111
2112 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h  handle, bool *mainapp)
2113 {
2114         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2115         retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2116         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2117
2118         if (info->app_info == NULL || info->app_info->mainapp == NULL)
2119                 return PMINFO_R_ERROR;
2120
2121         *mainapp = _get_bool_value(info->app_info->mainapp);
2122
2123         return PMINFO_R_OK;
2124 }
2125
2126 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
2127 {
2128         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2129         retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2130         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2131
2132         if (info->app_info == NULL || info->app_info->preload == NULL)
2133                 return PMINFO_R_ERROR;
2134
2135         *preload = _get_bool_value(info->app_info->preload);
2136
2137         return PMINFO_R_OK;
2138 }
2139
2140 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
2141 {
2142         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2143         retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2144         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2145
2146         if (info->app_info == NULL || info->app_info->submode == NULL)
2147                 return PMINFO_R_ERROR;
2148
2149         *submode = _get_bool_value(info->app_info->submode);
2150
2151         return PMINFO_R_OK;
2152 }
2153
2154 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
2155 {
2156         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2157
2158         if (handle == NULL || process_pool == NULL) {
2159                 LOGE("invalid parameter");
2160                 return PMINFO_R_EINVAL;
2161         }
2162
2163         if (info->app_info == NULL)
2164                 return PMINFO_R_ERROR;
2165
2166         *process_pool = _get_bool_value(info->app_info->process_pool);
2167
2168         return PMINFO_R_OK;
2169 }
2170
2171 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
2172 {
2173         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2174         retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
2175         retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
2176
2177         const char *val;
2178         GList *tmp;
2179         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2180
2181         if (info->app_info == NULL)
2182                 return PMINFO_R_ERROR;
2183
2184         *exist = 0;
2185         for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2186                 val = (const char *)tmp->data;
2187                 if (val == NULL)
2188                         continue;
2189                 if (strcasecmp(val, category) == 0) {
2190                         *exist = 1;
2191                         break;
2192                 }
2193         }
2194
2195         return PMINFO_R_OK;
2196 }
2197
2198 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
2199                 bool *ui_gadget)
2200 {
2201         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2202
2203         if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
2204                 _LOGE("invalid parameter");
2205                 return PMINFO_R_EINVAL;
2206         }
2207
2208         *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
2209
2210         return PMINFO_R_OK;
2211 }
2212
2213 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
2214                 bool *support_disable)
2215 {
2216         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2217
2218         if (info == NULL || info->app_info == NULL || support_disable == NULL) {
2219                 _LOGE("invalid parameter");
2220                 return PMINFO_R_EINVAL;
2221         }
2222
2223         *support_disable = _get_bool_value(info->app_info->support_disable);
2224
2225         return PMINFO_R_OK;
2226 }
2227
2228 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
2229 {
2230         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2231         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2232         __cleanup_appinfo(info);
2233         return PMINFO_R_OK;
2234 }
2235
2236 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
2237 {
2238         return (pkgmgrinfo_pkginfo_filter_create(handle));
2239 }
2240
2241 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
2242 {
2243         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2244 }
2245
2246 static gint __compare_func(gconstpointer data1, gconstpointer data2)
2247 {
2248         pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
2249         pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
2250         if (node1->prop == node2->prop)
2251                 return 0;
2252         else if (node1->prop > node2->prop)
2253                 return 1;
2254         else
2255                 return -1;
2256 }
2257
2258 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
2259                                 const char *property, const int value)
2260 {
2261         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2262         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2263         char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
2264         char *val = NULL;
2265         GSList *link = NULL;
2266         int prop = -1;
2267         prop = _pminfo_appinfo_convert_to_prop_int(property);
2268         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
2269                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
2270                 _LOGE("Invalid Integer Property\n");
2271                 return PMINFO_R_EINVAL;
2272         }
2273         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2274         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2275         if (node == NULL) {
2276                 _LOGE("Out of Memory!!!\n");
2277                 return PMINFO_R_ERROR;
2278         }
2279         snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
2280         val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
2281         if (val == NULL) {
2282                 _LOGE("Out of Memory\n");
2283                 free(node);
2284                 node = NULL;
2285                 return PMINFO_R_ERROR;
2286         }
2287         node->prop = prop;
2288         node->value = val;
2289         /*If API is called multiple times for same property, we should override the previous values.
2290         Last value set will be used for filtering.*/
2291         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2292         if (link)
2293                 filter->list = g_slist_delete_link(filter->list, link);
2294         filter->list = g_slist_append(filter->list, (gpointer)node);
2295         return PMINFO_R_OK;
2296
2297 }
2298
2299 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
2300                                 const char *property, const bool value)
2301 {
2302         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2303         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2304         char *val = NULL;
2305         GSList *link = NULL;
2306         int prop = -1;
2307         prop = _pminfo_appinfo_convert_to_prop_bool(property);
2308         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
2309                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
2310                 _LOGE("Invalid Boolean Property\n");
2311                 return PMINFO_R_EINVAL;
2312         }
2313         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2314         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2315         if (node == NULL) {
2316                 _LOGE("Out of Memory!!!\n");
2317                 return PMINFO_R_ERROR;
2318         }
2319         if (value)
2320                 val = strndup("('true','True')", 15);
2321         else
2322                 val = strndup("('false','False')", 17);
2323         if (val == NULL) {
2324                 _LOGE("Out of Memory\n");
2325                 free(node);
2326                 node = NULL;
2327                 return PMINFO_R_ERROR;
2328         }
2329         node->prop = prop;
2330         node->value = val;
2331         /*If API is called multiple times for same property, we should override the previous values.
2332         Last value set will be used for filtering.*/
2333         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2334         if (link)
2335                 filter->list = g_slist_delete_link(filter->list, link);
2336         filter->list = g_slist_append(filter->list, (gpointer)node);
2337         return PMINFO_R_OK;
2338
2339 }
2340
2341 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
2342                                 const char *property, const char *value)
2343 {
2344         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2345         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2346         retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2347         char *val = NULL;
2348         pkgmgrinfo_node_x *ptr = NULL;
2349         char prev[PKG_STRING_LEN_MAX] = {'\0'};
2350         char temp[PKG_STRING_LEN_MAX] = {'\0'};
2351         GSList *link = NULL;
2352         int prop = -1;
2353         prop = _pminfo_appinfo_convert_to_prop_str(property);
2354         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
2355                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
2356                 _LOGE("Invalid String Property\n");
2357                 return PMINFO_R_EINVAL;
2358         }
2359         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2360         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2361         if (node == NULL) {
2362                 _LOGE("Out of Memory!!!\n");
2363                 return PMINFO_R_ERROR;
2364         }
2365         node->prop = prop;
2366         switch (prop) {
2367         case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
2368                 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
2369                         val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
2370                 else
2371                         val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
2372                 node->value = val;
2373                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2374                 if (link)
2375                         filter->list = g_slist_delete_link(filter->list, link);
2376                 filter->list = g_slist_append(filter->list, (gpointer)node);
2377                 break;
2378         case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
2379         case E_PMINFO_APPINFO_PROP_APP_OPERATION:
2380         case E_PMINFO_APPINFO_PROP_APP_URI:
2381         case E_PMINFO_APPINFO_PROP_APP_MIME:
2382                 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
2383                 if (val == NULL) {
2384                         _LOGE("Out of Memory\n");
2385                         free(node);
2386                         node = NULL;
2387                         return PMINFO_R_ERROR;
2388                 }
2389                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2390                 if (link) {
2391                         ptr = (pkgmgrinfo_node_x *)link->data;
2392                         strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
2393                         _LOGE("Previous value is %s\n", prev);
2394                         filter->list = g_slist_delete_link(filter->list, link);
2395                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
2396                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
2397                         _LOGE("New value is %s\n", val);
2398                         node->value = val;
2399                         filter->list = g_slist_append(filter->list, (gpointer)node);
2400                         memset(temp, '\0', PKG_STRING_LEN_MAX);
2401                 } else {
2402                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
2403                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
2404                         _LOGE("First value is %s\n", val);
2405                         node->value = val;
2406                         filter->list = g_slist_append(filter->list, (gpointer)node);
2407                         memset(temp, '\0', PKG_STRING_LEN_MAX);
2408                 }
2409                 break;
2410         default:
2411                 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
2412                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2413                 if (link)
2414                         filter->list = g_slist_delete_link(filter->list, link);
2415                 filter->list = g_slist_append(filter->list, (gpointer)node);
2416                 break;
2417         }
2418         return PMINFO_R_OK;
2419 }
2420
2421 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
2422 {
2423         int ret;
2424         GList *list = NULL;
2425
2426         if (handle == NULL || count == NULL) {
2427                 _LOGE("invalid parameter");
2428                 return PMINFO_R_EINVAL;
2429         }
2430
2431         ret = _appinfo_get_filtered_list(handle, uid, &list);
2432         if (ret != PMINFO_R_OK)
2433                 return PMINFO_R_ERROR;
2434
2435         *count = g_list_length(list);
2436
2437         g_list_free_full(list, free);
2438
2439         return PMINFO_R_OK;
2440 }
2441
2442 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
2443 {
2444         return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
2445 }
2446
2447 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
2448                 pkgmgrinfo_appinfo_filter_h handle,
2449                 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2450 {
2451         if (handle == NULL || app_cb == NULL) {
2452                 LOGE("invalid parameter");
2453                 return PMINFO_R_EINVAL;
2454         }
2455
2456         return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2457                         user_data);
2458 }
2459
2460 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
2461                                 pkgmgrinfo_app_list_cb app_cb, void * user_data)
2462 {
2463         return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
2464 }
2465
2466 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
2467 {
2468         return (pkgmgrinfo_pkginfo_filter_create(handle));
2469 }
2470
2471 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
2472 {
2473         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2474 }
2475
2476 API int pkgmgrinfo_appinfo_metadata_filter_add(
2477                 pkgmgrinfo_appinfo_metadata_filter_h handle,
2478                 const char *key, const char *value)
2479 {
2480         int ret;
2481
2482         ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2483                         PMINFO_APPINFO_PROP_APP_METADATA_KEY, key);
2484         if (ret != PMINFO_R_OK)
2485                 return ret;
2486
2487         /* value can be NULL.
2488          * In that case all apps with specified key should be displayed
2489          */
2490         if (value) {
2491                 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2492                                 PMINFO_APPINFO_PROP_APP_METADATA_VALUE, value);
2493                 if (ret != PMINFO_R_OK)
2494                         return ret;
2495         }
2496
2497         return PMINFO_R_OK;
2498 }
2499
2500 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2501                 pkgmgrinfo_appinfo_metadata_filter_h handle,
2502                 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2503 {
2504         if (handle == NULL || app_cb == NULL) {
2505                 LOGE("invalid parameter");
2506                 return PMINFO_R_EINVAL;
2507         }
2508
2509         return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2510                         user_data);
2511 }
2512
2513 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
2514                 pkgmgrinfo_appinfo_metadata_filter_h handle,
2515                 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2516 {
2517         return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
2518                         user_data, GLOBAL_USER);
2519 }
2520
2521 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2522 {
2523         const char *val;
2524         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2525
2526         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2527         retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2528
2529         val = info->app_info->guestmode_visibility;
2530         *status = _get_bool_value(val);
2531         return PMINFO_R_OK;
2532 }