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