fix queries to send all appinfo to AMD
[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, &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         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, &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(const 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, app_effective_appid "
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         _save_column_str(stmt, idx++, &info->effective_appid);
674
675         info->background_category = __get_background_category(bg_category_str);
676         free(bg_category_str);
677
678         if (_appinfo_get_label(db, info->appid, locale, &info->label)) {
679                 pkgmgrinfo_basic_free_application(info);
680                 sqlite3_finalize(stmt);
681                 return PMINFO_R_ERROR;
682         }
683
684         if (_appinfo_get_icon(db, info->appid, locale, &info->icon)) {
685                 pkgmgrinfo_basic_free_application(info);
686                 sqlite3_finalize(stmt);
687                 return PMINFO_R_ERROR;
688         }
689
690         if (_appinfo_get_category(db, info->appid, &info->category)) {
691                 pkgmgrinfo_basic_free_application(info);
692                 sqlite3_finalize(stmt);
693                 return PMINFO_R_ERROR;
694         }
695
696         if (_appinfo_get_app_control(db, info->appid, &info->appcontrol)) {
697                 pkgmgrinfo_basic_free_application(info);
698                 sqlite3_finalize(stmt);
699                 return PMINFO_R_ERROR;
700         }
701
702         if (_appinfo_get_data_control(db, info->appid, &info->datacontrol)) {
703                 pkgmgrinfo_basic_free_application(info);
704                 sqlite3_finalize(stmt);
705                 return PMINFO_R_ERROR;
706         }
707
708         if (_appinfo_get_metadata(db, info->appid, &info->metadata)) {
709                 pkgmgrinfo_basic_free_application(info);
710                 sqlite3_finalize(stmt);
711                 return PMINFO_R_ERROR;
712         }
713
714         if (_appinfo_get_splashscreens(db, info->appid, &info->splashscreens)) {
715                 pkgmgrinfo_basic_free_application(info);
716                 sqlite3_finalize(stmt);
717                 return PMINFO_R_ERROR;
718         }
719
720         info->for_all_users = strdup((db_uid != GLOBAL_USER) ? "false" : "true");
721
722         *application = info;
723
724         sqlite3_finalize(stmt);
725
726         return PMINFO_R_OK;
727 }
728
729 static int _appinfo_get_appinfo(const char *appid, uid_t db_uid,
730                 uid_t target_uid, bool is_disabled, pkgmgr_appinfo_x **appinfo)
731 {
732         int ret;
733         sqlite3 *db;
734         const char *dbpath;
735         char *locale;
736         pkgmgr_appinfo_x *info;
737
738         dbpath = getUserPkgParserDBPathUID(db_uid);
739         if (dbpath == NULL)
740                 return PMINFO_R_ERROR;
741
742         locale = _get_system_locale();
743         if (locale == NULL)
744                 return PMINFO_R_ERROR;
745
746         ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
747         if (ret != SQLITE_OK) {
748                 _LOGE("failed to open db: %d", ret);
749                 free(locale);
750                 return PMINFO_R_ERROR;
751         }
752
753         info = calloc(1, sizeof(pkgmgr_appinfo_x));
754         if (info == NULL) {
755                 _LOGE("out of memory");
756                 free(locale);
757                 sqlite3_close_v2(db);
758                 return PMINFO_R_ERROR;
759         }
760
761         ret = _appinfo_get_application(db, appid, locale, &info->app_info, is_disabled, db_uid, target_uid);
762         if (ret != PMINFO_R_OK) {
763                 free(info);
764                 free(locale);
765                 sqlite3_close_v2(db);
766                 return ret;
767         }
768
769         info->locale = locale;
770         info->package = strdup(info->app_info->package);
771
772         *appinfo = info;
773
774         sqlite3_close_v2(db);
775
776         return ret;
777 }
778
779 int _appinfo_get_applist(uid_t uid, const char *locale, GHashTable **appinfo_table)
780 {
781         int ret = PMINFO_R_ERROR;
782         int idx = 0;
783         const char *dbpath;
784         char *query = NULL;
785         char *bg_category_str = NULL;
786         char *key = NULL;
787         sqlite3 *db;
788         sqlite3_stmt *stmt = NULL;
789         pkgmgr_appinfo_x *info = NULL;
790         application_x *appinfo = NULL;
791
792         dbpath = getUserPkgParserDBPathUID(uid);
793         if (dbpath == NULL)
794                 return PMINFO_R_ERROR;
795
796         ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
797         if (ret != SQLITE_OK) {
798                 _LOGE("failed to open db: %d", ret);
799                 ret = PMINFO_R_ERROR;
800                 goto catch;
801         }
802
803         query = sqlite3_mprintf("SELECT app_id, app_exec, app_type, "
804                         "app_onboot, app_multiple, app_autorestart, app_taskmanage, "
805                         "app_hwacceleration, app_permissiontype, app_preload, "
806                         "app_installed_storage, app_process_pool, app_launch_mode, "
807                         "app_package_type, component_type, package, app_tep_name, "
808                         "app_background_category, app_root_path, app_api_version, "
809                         "app_effective_appid, (CASE WHEN A.app_disable='true' THEN 'true' "
810                         "ELSE (CASE WHEN (SELECT app_id FROM package_app_disable_for_user "
811                         "WHERE app_id=A.app_id AND uid='%d') IS NULL "
812                         "THEN 'false' ELSE 'true' END) END) AS app_disable "
813                         "FROM package_app_info A", (int)getuid());
814
815         if (query == NULL) {
816                 _LOGE("Out of memory");
817                 goto catch;
818         }
819
820         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
821         if (ret != SQLITE_OK) {
822                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
823                 ret = PMINFO_R_ERROR;
824                 goto catch;
825         }
826
827         while (sqlite3_step(stmt) == SQLITE_ROW) {
828                 info = calloc(1, sizeof(pkgmgr_appinfo_x));
829                 appinfo = calloc(1, sizeof(application_x));
830                 if (info == NULL || appinfo == NULL) {
831                         LOGE("calloc failed");
832                         ret = PMINFO_R_ERROR;
833                         goto catch;
834                 }
835
836                 idx = 0;
837                 _save_column_str(stmt, idx++, &appinfo->appid);
838                 _save_column_str(stmt, idx++, &appinfo->exec);
839                 _save_column_str(stmt, idx++, &appinfo->type);
840
841                 _save_column_str(stmt, idx++, &appinfo->onboot);
842                 _save_column_str(stmt, idx++, &appinfo->multiple);
843                 _save_column_str(stmt, idx++, &appinfo->autorestart);
844                 _save_column_str(stmt, idx++, &appinfo->taskmanage);
845
846                 _save_column_str(stmt, idx++, &appinfo->hwacceleration);
847                 _save_column_str(stmt, idx++, &appinfo->permission_type);
848                 _save_column_str(stmt, idx++, &appinfo->preload);
849
850                 _save_column_str(stmt, idx++, &appinfo->installed_storage);
851                 _save_column_str(stmt, idx++, &appinfo->process_pool);
852                 _save_column_str(stmt, idx++, &appinfo->launch_mode);
853
854                 _save_column_str(stmt, idx++, &appinfo->package_type);
855                 _save_column_str(stmt, idx++, &appinfo->component_type);
856                 _save_column_str(stmt, idx++, &appinfo->package);
857                 _save_column_str(stmt, idx++, &appinfo->tep_name);
858
859                 _save_column_str(stmt, idx++, &bg_category_str);
860                 _save_column_str(stmt, idx++, &appinfo->root_path);
861                 _save_column_str(stmt, idx++, &appinfo->api_version);
862
863                 _save_column_str(stmt, idx++, &appinfo->effective_appid);
864                 _save_column_str(stmt, idx++, &appinfo->is_disabled);
865
866                 appinfo->background_category = __get_background_category(bg_category_str);
867                 free(bg_category_str);
868
869                 if (_appinfo_get_splashscreens(db, appinfo->appid, &appinfo->splashscreens)) {
870                         pkgmgrinfo_basic_free_application(appinfo);
871                         ret = PMINFO_R_ERROR;
872                         goto catch;
873                 }
874
875                 info->locale = strdup(locale);
876                 info->package = strdup(appinfo->package);
877                 appinfo->for_all_users = strdup((uid != GLOBAL_USER) ? "false" : "true");
878                 info->app_info = appinfo;
879                 key = strdup(info->app_info->appid);
880
881                 if (!g_hash_table_contains(*appinfo_table, (gconstpointer)key))
882                         g_hash_table_insert(*appinfo_table, (gpointer)key, (gpointer)info);
883                 else
884                         __cleanup_appinfo(info);
885         }
886
887         ret = PMINFO_R_OK;
888
889 catch:
890
891         sqlite3_finalize(stmt);
892         sqlite3_free(query);
893         sqlite3_close(db);
894
895         return ret;
896 }
897
898 API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid,
899                 pkgmgrinfo_appinfo_h *handle)
900 {
901         int ret;
902
903         if (appid == NULL || handle == NULL) {
904                 LOGE("invalid parameter");
905                 return PMINFO_R_EINVAL;
906         }
907
908         ret = _appinfo_get_appinfo(appid, uid, uid, true, (pkgmgr_appinfo_x **)handle);
909         if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
910                 ret = _appinfo_get_appinfo(appid, GLOBAL_USER, uid, true,
911                                 (pkgmgr_appinfo_x **)handle);
912
913         if (ret != PMINFO_R_OK)
914                 _LOGE("failed to get appinfo of %s for user %d", appid, uid);
915
916         return ret;
917 }
918
919 API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
920 {
921         return pkgmgrinfo_appinfo_get_usr_disabled_appinfo(appid, GLOBAL_USER, handle);
922 }
923
924 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
925                 pkgmgrinfo_appinfo_h *handle)
926 {
927         int ret;
928
929         if (appid == NULL || handle == NULL) {
930                 LOGE("invalid parameter");
931                 return PMINFO_R_EINVAL;
932         }
933
934         ret = _appinfo_get_appinfo(appid, uid, uid, false, (pkgmgr_appinfo_x **)handle);
935         if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
936                 ret = _appinfo_get_appinfo(appid, GLOBAL_USER, uid, false,
937                                 (pkgmgr_appinfo_x **)handle);
938         if (ret != PMINFO_R_OK)
939                 _LOGE("failed to get appinfo of %s for user %d", appid, uid);
940
941         return ret;
942 }
943
944 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
945 {
946         return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
947 }
948
949 static gpointer __copy_str(gconstpointer src, gpointer data)
950 {
951         const char *tmp = (const char *)src;
952         char *buffer;
953
954         buffer = strdup(tmp);
955         if (buffer == NULL) {
956                 LOGE("memory alloc failed");
957                 *(int *)data = -1;
958                 return NULL;
959         }
960
961         return buffer;
962 }
963
964 static gpointer __copy_label(gconstpointer src, gpointer data)
965 {
966         label_x *tmp = (label_x *)src;
967         label_x *label;
968
969         label = calloc(1, sizeof(label_x));
970         if (label == NULL) {
971                 LOGE("memory alloc failed");
972                 *(int *)data = -1;
973                 return NULL;
974         }
975
976         if (tmp->name)
977                 label->name = strdup(tmp->name);
978         if (tmp->text)
979                 label->text = strdup(tmp->text);
980         if (tmp->lang)
981                 label->lang = strdup(tmp->lang);
982
983         return label;
984 }
985
986 static gpointer __copy_icon(gconstpointer src, gpointer data)
987 {
988         icon_x *tmp = (icon_x *)src;
989         icon_x *icon;
990
991         icon = calloc(1, sizeof(icon_x));
992         if (icon== NULL) {
993                 LOGE("memory alloc failed");
994                 *(int *)data = -1;
995                 return NULL;
996         }
997
998         if (tmp->text)
999                 icon->text = strdup(tmp->text);
1000         if (tmp->lang)
1001                 icon->lang = strdup(tmp->lang);
1002         if (tmp->section)
1003                 icon->section = strdup(tmp->section);
1004         if (tmp->size)
1005                 icon->size = strdup(tmp->size);
1006         if (tmp->resolution)
1007                 icon->resolution = strdup(tmp->resolution);
1008
1009         return icon;
1010 }
1011
1012 static gpointer __copy_metadata(gconstpointer src, gpointer data)
1013 {
1014         metadata_x *tmp = (metadata_x *)src;
1015         metadata_x *metadata;
1016
1017         metadata = calloc(1, sizeof(metadata_x));
1018         if (metadata == NULL) {
1019                 LOGE("memory alloc failed");
1020                 *(int *)data = -1;
1021                 return NULL;
1022         }
1023
1024         if (tmp->key)
1025                 metadata->key = strdup(tmp->key);
1026         if (tmp->value)
1027                 metadata->value = strdup(tmp->value);
1028
1029         return metadata;
1030 }
1031
1032 static gpointer __copy_datacontrol(gconstpointer src, gpointer data)
1033 {
1034         datacontrol_x *tmp = (datacontrol_x *)src;
1035         datacontrol_x *datacontrol;
1036
1037         datacontrol = calloc(1, sizeof(datacontrol_x));
1038         if (datacontrol == NULL) {
1039                 LOGE("memory alloc failed");
1040                 *(int *)data = -1;
1041                 return NULL;
1042         }
1043
1044         if (tmp->providerid)
1045                 datacontrol->providerid = strdup(tmp->providerid);
1046         if (tmp->access)
1047                 datacontrol->access = strdup(tmp->access);
1048         if (tmp->type)
1049                 datacontrol->type = strdup(tmp->type);
1050
1051         return datacontrol;
1052 }
1053
1054 static gpointer __copy_appcontrol(gconstpointer src, gpointer data)
1055 {
1056         appcontrol_x *tmp = (appcontrol_x *)src;
1057         appcontrol_x *appcontrol;
1058
1059         appcontrol = calloc(1, sizeof(appcontrol_x));
1060         if (appcontrol ==NULL) {
1061                 LOGE("memory alloc failed");
1062                 *(int *)data = -1;
1063                 return NULL;
1064         }
1065
1066         if (tmp->operation)
1067                 appcontrol->operation = strdup(tmp->operation);
1068         if (tmp->uri)
1069                 appcontrol->uri = strdup(tmp->uri);
1070         if (tmp->mime)
1071                 appcontrol->mime = strdup(tmp->mime);
1072
1073         return appcontrol;
1074 }
1075
1076 static gpointer __copy_splashscreens(gconstpointer src, gpointer data)
1077 {
1078         splashscreen_x *tmp = (splashscreen_x *)src;
1079         splashscreen_x *splashscreen;
1080
1081         splashscreen = (splashscreen_x *)calloc(1, sizeof(splashscreen_x));
1082         if (splashscreen == NULL) {
1083                 LOGE("memory alloc failed");
1084                 *(int *)data = -1;
1085                 return NULL;
1086         }
1087
1088         if (tmp->src)
1089                 splashscreen->src = strdup(tmp->src);
1090         if (tmp->type)
1091                 splashscreen->type = strdup(tmp->type);
1092         if (tmp->orientation)
1093                 splashscreen->orientation = strdup(tmp->orientation);
1094         if (tmp->indicatordisplay)
1095                 splashscreen->indicatordisplay = strdup(tmp->indicatordisplay);
1096         if (tmp->operation)
1097                 splashscreen->operation = strdup(tmp->operation);
1098
1099         return splashscreen;
1100 }
1101
1102 static int _appinfo_copy_appinfo(application_x **application, application_x *data)
1103 {
1104         application_x *app_info;
1105         int ret;
1106
1107         app_info = calloc(1, sizeof(application_x));
1108         if (app_info == NULL) {
1109                 LOGE("memory alloc failed");
1110                 return PMINFO_R_ERROR;
1111         }
1112
1113         if (data->appid != NULL)
1114                 app_info->appid = strdup(data->appid);
1115         if (data->exec != NULL)
1116                 app_info->exec = strdup(data->exec);
1117         if (data->nodisplay != NULL)
1118                 app_info->nodisplay = strdup(data->nodisplay);
1119         if (data->multiple != NULL)
1120                 app_info->multiple = strdup(data->multiple);
1121         if (data->taskmanage != NULL)
1122                 app_info->taskmanage = strdup(data->taskmanage);
1123         if (data->enabled != NULL)
1124                 app_info->enabled = strdup(data->enabled);
1125         if (data->type != NULL)
1126                 app_info->type = strdup(data->type);
1127         if (data->categories != NULL)
1128                 app_info->categories = strdup(data->categories);
1129         if (data->hwacceleration != NULL)
1130                 app_info->hwacceleration = strdup(data->hwacceleration);
1131         if (data->screenreader != NULL)
1132                 app_info->screenreader = strdup(data->screenreader);
1133         if (data->mainapp != NULL)
1134                 app_info->mainapp = strdup(data->mainapp);
1135         if (data->package != NULL)
1136                 app_info->package = strdup(data->package);
1137         if (data->recentimage != NULL)
1138                 app_info->recentimage = strdup(data->recentimage);
1139         if (data->launchcondition != NULL)
1140                 app_info->launchcondition = strdup(data->launchcondition);
1141         if (data->indicatordisplay != NULL)
1142                 app_info->indicatordisplay = strdup(data->indicatordisplay);
1143         if (data->portraitimg != NULL)
1144                 app_info->portraitimg = strdup(data->portraitimg);
1145         if (data->landscapeimg != NULL)
1146                 app_info->landscapeimg = strdup(data->landscapeimg);
1147         if (data->guestmode_visibility != NULL)
1148                 app_info->guestmode_visibility = strdup(data->guestmode_visibility);
1149         if (data->component != NULL)
1150                 app_info->component = strdup(data->component);
1151         if (data->permission_type != NULL)
1152                 app_info->permission_type = strdup(data->permission_type);
1153         if (data->component_type != NULL)
1154                 app_info->component_type = strdup(data->component_type);
1155         if (data->preload != NULL)
1156                 app_info->preload = strdup(data->preload);
1157         if (data->submode != NULL)
1158                 app_info->submode = strdup(data->submode);
1159         if (data->submode_mainid != NULL)
1160                 app_info->submode_mainid = strdup(data->submode_mainid);
1161         if (data->process_pool != NULL)
1162                 app_info->process_pool = strdup(data->process_pool);
1163         if (data->installed_storage != NULL)
1164                 app_info->installed_storage = strdup(data->installed_storage);
1165         if (data->autorestart != NULL)
1166                 app_info->autorestart = strdup(data->autorestart);
1167         if (data->onboot != NULL)
1168                 app_info->onboot = strdup(data->onboot);
1169         if (data->support_disable != NULL)
1170                 app_info->support_disable = strdup(data->support_disable);
1171         if (data->ui_gadget != NULL)
1172                 app_info->ui_gadget = strdup(data->ui_gadget);
1173         if (data->launch_mode != NULL)
1174                 app_info->launch_mode = strdup(data->launch_mode);
1175         if (data->package_type != NULL)
1176                 app_info->package_type = strdup(data->package_type);
1177         if (data->effective_appid != NULL)
1178                 app_info->effective_appid = strdup(data->effective_appid);
1179
1180         /* GList */
1181         ret = 0;
1182         app_info->label = g_list_copy_deep(data->label, __copy_label, &ret);
1183         if (ret < 0) {
1184                 LOGE("memory alloc failed");
1185                 pkgmgrinfo_basic_free_application(app_info);
1186                 return PMINFO_R_ERROR;
1187         }
1188
1189         ret = 0;
1190         app_info->icon = g_list_copy_deep(data->icon, __copy_icon, &ret);
1191         if (ret < 0) {
1192                 LOGE("memory alloc failed");
1193                 pkgmgrinfo_basic_free_application(app_info);
1194                 return PMINFO_R_ERROR;
1195         }
1196
1197         ret = 0;
1198         app_info->category = g_list_copy_deep(data->category, __copy_str, &ret);
1199         if (ret < 0) {
1200                 LOGE("memory alloc failed");
1201                 pkgmgrinfo_basic_free_application(app_info);
1202                 return PMINFO_R_ERROR;
1203         }
1204
1205         ret = 0;
1206         app_info->metadata = g_list_copy_deep(data->metadata, __copy_metadata, &ret);
1207         if (ret < 0) {
1208                 LOGE("memory alloc failed");
1209                 pkgmgrinfo_basic_free_application(app_info);
1210                 return PMINFO_R_ERROR;
1211         }
1212
1213         ret = 0;
1214         app_info->datacontrol = g_list_copy_deep(data->datacontrol, __copy_datacontrol, &ret);
1215         if (ret < 0) {
1216                 LOGE("memory alloc failed");
1217                 pkgmgrinfo_basic_free_application(app_info);
1218                 return PMINFO_R_ERROR;
1219         }
1220
1221         ret = 0;
1222         app_info->appcontrol = g_list_copy_deep(data->appcontrol, __copy_appcontrol, &ret);
1223         if (ret < 0) {
1224                 LOGE("memory alloc failed");
1225                 pkgmgrinfo_basic_free_application(app_info);
1226                 return PMINFO_R_ERROR;
1227         }
1228
1229         ret = 0;
1230         app_info->background_category = g_list_copy_deep(data->background_category, __copy_str, &ret);
1231         if (ret < 0) {
1232                 LOGE("memory alloc failed");
1233                 pkgmgrinfo_basic_free_application(app_info);
1234                 return PMINFO_R_ERROR;
1235         }
1236
1237         ret = 0;
1238         app_info->splashscreens = g_list_copy_deep(data->splashscreens, __copy_splashscreens, &ret);
1239         if (ret < 0) {
1240                 LOGE("memory alloc failed");
1241                 pkgmgrinfo_basic_free_application(app_info);
1242                 return PMINFO_R_ERROR;
1243         }
1244
1245         *application = app_info;
1246
1247         return PMINFO_R_OK;
1248 }
1249
1250 API int pkgmgrinfo_appinfo_clone_appinfo(pkgmgrinfo_appinfo_h handle,
1251                 pkgmgrinfo_appinfo_h *clone)
1252 {
1253         pkgmgr_appinfo_x *info;
1254         pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle;
1255
1256         if (handle == NULL)
1257                 return PMINFO_R_EINVAL;
1258
1259         info = calloc(1, sizeof(pkgmgr_appinfo_x));
1260         if (info == NULL) {
1261                 LOGE("memory alloc failed");
1262                 return PMINFO_R_ERROR;
1263         }
1264
1265         if (temp->package != NULL)
1266                 info->package = strdup(temp->package);
1267         if (temp->locale != NULL)
1268                 info->locale = strdup(temp->locale);
1269
1270         info->app_component = temp->app_component;
1271
1272         if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) {
1273                 LOGE("appinfo copy failed");
1274                 if (info->package)
1275                         free((void *)info->package);
1276                 if (info->locale)
1277                         free(info->locale);
1278                 free(info);
1279                 return PMINFO_R_ERROR;
1280         }
1281
1282         *clone = info;
1283
1284         return PMINFO_R_OK;
1285 }
1286
1287 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
1288                 pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb,
1289                 void *user_data)
1290 {
1291         int ret;
1292         pkgmgr_appinfo_x *info;
1293         GList *list = NULL;
1294         GList *tmp;
1295         char *appid;
1296         int stop = 0;
1297
1298         ret = _appinfo_get_filtered_list(filter, uid, &list);
1299         if (ret != PMINFO_R_OK)
1300                 return PMINFO_R_ERROR;
1301
1302         for (tmp = list; tmp; tmp = tmp->next) {
1303                 appid = (char *)tmp->data;
1304                 if (stop == 0) {
1305                         ret = _appinfo_get_appinfo(appid, uid, uid, false, &info);
1306                         if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
1307                                 ret = _appinfo_get_appinfo(appid, GLOBAL_USER, uid, false,
1308                                                 &info);
1309                         if (ret != PMINFO_R_OK) {
1310                                 free(appid);
1311                                 continue;
1312                         }
1313                         if (app_list_cb(info, user_data) < 0)
1314                                 stop = 1;
1315                         pkgmgrinfo_appinfo_destroy_appinfo(info);
1316                 }
1317                 free(appid);
1318         }
1319
1320         g_list_free(list);
1321
1322         return PMINFO_R_OK;
1323 }
1324
1325 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
1326                 pkgmgrinfo_app_component component,
1327                 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
1328 {
1329         int ret;
1330         pkgmgrinfo_appinfo_filter_h filter;
1331         char *pkgid;
1332         const char *comp_str = NULL;
1333
1334         if (handle == NULL || app_func == NULL) {
1335                 LOGE("invalid parameter");
1336                 return PMINFO_R_EINVAL;
1337         }
1338
1339         if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
1340                 LOGE("invalid parameter");
1341                 return PMINFO_R_EINVAL;
1342         }
1343
1344         if (pkgmgrinfo_appinfo_filter_create(&filter))
1345                 return PMINFO_R_ERROR;
1346
1347         if (pkgmgrinfo_appinfo_filter_add_string(filter,
1348                                 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
1349                 pkgmgrinfo_appinfo_filter_destroy(filter);
1350                 return PMINFO_R_ERROR;
1351         }
1352
1353         if (uid == GLOBAL_USER) {
1354                 if (pkgmgrinfo_appinfo_filter_add_int(filter,
1355                                         PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER, (int)getuid())) {
1356                         pkgmgrinfo_appinfo_filter_destroy(filter);
1357                         return PMINFO_R_ERROR;
1358                 }
1359         }
1360
1361         switch (component) {
1362         case PMINFO_UI_APP:
1363                 comp_str = PMINFO_APPINFO_UI_APP;
1364                 break;
1365         case PMINFO_SVC_APP:
1366                 comp_str = PMINFO_APPINFO_SVC_APP;
1367                 break;
1368         default:
1369                 break;
1370         }
1371
1372         if (comp_str) {
1373                 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1374                                         PMINFO_APPINFO_PROP_APP_COMPONENT,
1375                                         comp_str)) {
1376                         pkgmgrinfo_appinfo_filter_destroy(filter);
1377                         return PMINFO_R_ERROR;
1378                 }
1379         }
1380
1381         ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, app_func,
1382                         user_data);
1383
1384         pkgmgrinfo_appinfo_filter_destroy(filter);
1385
1386         return ret;
1387 }
1388
1389 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
1390                                                 pkgmgrinfo_app_list_cb app_func, void *user_data)
1391 {
1392         return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
1393 }
1394
1395 API int pkgmgrinfo_appinfo_get_usr_applist_for_amd(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1396 {
1397         int ret = PMINFO_R_ERROR;
1398         char *locale = NULL;
1399         GHashTable *appinfo_table;
1400         GHashTableIter iter;
1401         char *key;
1402         pkgmgr_appinfo_x *val;
1403
1404         locale = _get_system_locale();
1405         if (locale == NULL)
1406                 return PMINFO_R_ERROR;
1407
1408         appinfo_table = g_hash_table_new_full(g_str_hash, g_str_equal,
1409                         free, __free_appinfo_list);
1410         if (appinfo_table == NULL) {
1411                 ret = -1;
1412                 goto catch;
1413         }
1414
1415         ret = _appinfo_get_applist(uid, locale, &appinfo_table);
1416         if (ret != PMINFO_R_OK) {
1417                 LOGE("failed get applist[%d]", (int)uid);
1418                 goto catch;
1419         }
1420
1421         if (uid != GLOBAL_USER) {
1422                 ret = _appinfo_get_applist(GLOBAL_USER, locale, &appinfo_table);
1423                 if (ret != PMINFO_R_OK) {
1424                         LOGE("failed get applist[%d]", GLOBAL_USER);
1425                         goto catch;
1426                 }
1427         }
1428
1429         g_hash_table_iter_init(&iter, appinfo_table);
1430         while (g_hash_table_iter_next(&iter, (gpointer)&key, (gpointer)&val)) {
1431                 ret = app_func((void *)val, user_data);
1432                 if (ret != PMINFO_R_OK) {
1433                         LOGE("callback is stopped");
1434                         goto catch;
1435                 }
1436         }
1437
1438 catch:
1439         if (locale)
1440                 free(locale);
1441
1442         if (appinfo_table)
1443                 g_hash_table_destroy(appinfo_table);
1444
1445         return ret;
1446 }
1447
1448 API int pkgmgrinfo_appinfo_get_applist_for_amd(pkgmgrinfo_app_list_cb app_func, void *user_data)
1449 {
1450         return pkgmgrinfo_appinfo_get_usr_applist_for_amd(app_func, GLOBAL_USER, user_data);
1451 }
1452
1453 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1454 {
1455         if (app_func == NULL) {
1456                 LOGE("invalid parameter");
1457                 return PMINFO_R_EINVAL;
1458         }
1459
1460         return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
1461                         user_data);
1462 }
1463
1464 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
1465 {
1466         return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
1467 }
1468
1469 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
1470 {
1471         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1472
1473         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1474         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1475
1476         if (info->app_info == NULL || info->app_info->appid == NULL)
1477                 return PMINFO_R_ERROR;
1478         *appid = (char *)info->app_info->appid;
1479
1480         return PMINFO_R_OK;
1481 }
1482
1483 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
1484 {
1485         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1486
1487         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1488         retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1489
1490         if (info->package == NULL)
1491                 return PMINFO_R_ERROR;
1492
1493         *pkg_name = (char *)info->package;
1494
1495         return PMINFO_R_OK;
1496 }
1497
1498 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
1499 {
1500         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1501
1502         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1503         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1504
1505         if (info->package == NULL)
1506                 return PMINFO_R_ERROR;
1507
1508         *pkgid = (char *)info->package;
1509
1510         return PMINFO_R_OK;
1511 }
1512
1513 API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h  handle, char **pkgtype)
1514 {
1515         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1516         retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1517         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1518
1519         *pkgtype = (char *)info->app_info->package_type;
1520
1521         return PMINFO_R_OK;
1522 }
1523
1524 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
1525 {
1526         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1527
1528         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1529         retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1530
1531         if (info->app_info == NULL || info->app_info->exec == NULL)
1532                 return PMINFO_R_ERROR;
1533         *exec = (char *)info->app_info->exec;
1534
1535         return PMINFO_R_OK;
1536 }
1537
1538
1539 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1540 {
1541         const char *locale;
1542         icon_x *ptr;
1543         GList *tmp;
1544         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1545
1546         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1547         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1548
1549         locale = info->locale;
1550         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1551
1552         if (info->app_info == NULL)
1553                 return PMINFO_R_ERROR;
1554
1555         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1556                 ptr = (icon_x *)tmp->data;
1557                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1558                                 !strcasecmp(ptr->text, "") ||
1559                                 strcmp(ptr->lang, locale))
1560                         continue;
1561                 *icon = (char *)ptr->text;
1562                 return PMINFO_R_OK;
1563         }
1564
1565         locale = DEFAULT_LOCALE;
1566         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1567                 ptr = (icon_x *)tmp->data;
1568                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1569                                 strcmp(ptr->lang, locale))
1570                         continue;
1571                 *icon = (char *)ptr->text;
1572                 return PMINFO_R_OK;
1573         }
1574
1575         return PMINFO_R_ERROR;
1576 }
1577
1578
1579 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
1580 {
1581         const char *locale;
1582         label_x *ptr;
1583         GList *tmp;
1584         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1585
1586         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1587         retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1588
1589         locale = info->locale;
1590         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1591
1592         if (info->app_info == NULL)
1593                 return PMINFO_R_ERROR;
1594
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         locale = DEFAULT_LOCALE;
1605         for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1606                 ptr = (label_x *)tmp->data;
1607                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1608                                 strcmp(ptr->lang, locale))
1609                         continue;
1610                 *label = (char *)ptr->text;
1611                 return PMINFO_R_OK;
1612         }
1613
1614         return PMINFO_R_ERROR;
1615 }
1616
1617 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1618 {
1619         char *result = NULL;
1620         char *query = NULL;
1621         sqlite3_stmt *stmt = NULL;
1622         sqlite3 *db = NULL;
1623         char *val;
1624         const char *manifest_db;
1625
1626         manifest_db = getUserPkgParserDBPathUID(uid);
1627         if (manifest_db == NULL) {
1628                 _LOGE("Failed to get manifest db path");
1629                 goto err;
1630         }
1631
1632         if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
1633                 _LOGE("DB open fail\n");
1634                 goto err;
1635         }
1636
1637         query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1638         if (query == NULL) {
1639                 _LOGE("Out of memory");
1640                 goto err;
1641         }
1642
1643         if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1644                 _LOGE("prepare_v2 fail\n");
1645                 goto err;
1646         }
1647
1648         if (sqlite3_step(stmt) == SQLITE_ROW) {
1649                 val = (char *)sqlite3_column_text(stmt, 0);
1650                 if (val != NULL)
1651                         result = strdup(val);
1652         }
1653
1654 err:
1655         sqlite3_finalize(stmt);
1656         sqlite3_free(query);
1657         sqlite3_close(db);
1658
1659         return result;
1660 }
1661
1662 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1663 {
1664         char *val;
1665
1666         retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1667
1668         val = _get_localed_label(appid, locale, uid);
1669         if (val == NULL)
1670                 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1671
1672         if (val == NULL)
1673                 return PMINFO_R_ERROR;
1674
1675         *label = val;
1676
1677         return PMINFO_R_OK;
1678 }
1679
1680 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1681 {
1682         return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
1683 }
1684
1685 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1686 {
1687         if (strcasecmp(comp, "uiapp") == 0)
1688                 return PMINFO_UI_APP;
1689         else if (strcasecmp(comp, "svcapp") == 0)
1690                 return PMINFO_SVC_APP;
1691         else if (strcasecmp(comp, "widgetapp") == 0)
1692                 return PMINFO_WIDGET_APP;
1693         else if (strcasecmp(comp, "watchapp") == 0)
1694                 return PMINFO_WATCH_APP;
1695         else
1696                 return -1;
1697 }
1698
1699 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1700 {
1701         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1702         int comp;
1703
1704         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1705         retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1706
1707         if (info->app_info == NULL)
1708                 return PMINFO_R_ERROR;
1709
1710         comp = __appcomponent_convert(info->app_info->component);
1711         if (comp < 0)
1712                 return PMINFO_R_ERROR;
1713
1714         *component = comp;
1715
1716         return PMINFO_R_OK;
1717 }
1718
1719 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1720 {
1721         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1722
1723         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1724         retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1725
1726         if (info->app_info == NULL || info->app_info->type == NULL)
1727                 return PMINFO_R_ERROR;
1728         *app_type = (char *)info->app_info->type;
1729
1730         return PMINFO_R_OK;
1731 }
1732
1733 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h  handle,
1734                                         int *operation_count, char ***operation)
1735 {
1736         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1737         retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1738         retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1739         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1740         *operation_count = data->operation_count;
1741         *operation = data->operation;
1742         return PMINFO_R_OK;
1743 }
1744
1745 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h  handle,
1746                                         int *uri_count, char ***uri)
1747 {
1748         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1749         retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1750         retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1751         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1752         *uri_count = data->uri_count;
1753         *uri = data->uri;
1754         return PMINFO_R_OK;
1755 }
1756
1757 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h  handle,
1758                                         int *mime_count, char ***mime)
1759 {
1760         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1761         retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1762         retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1763         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1764         *mime_count = data->mime_count;
1765         *mime = data->mime;
1766         return PMINFO_R_OK;
1767 }
1768
1769 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h  handle,
1770                                         int *subapp_count, char ***subapp)
1771 {
1772         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1773         retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1774         retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1775         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1776         *subapp_count = data->subapp_count;
1777         *subapp = data->subapp;
1778         return PMINFO_R_OK;
1779 }
1780
1781 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1782 {
1783         char *val;
1784         icon_x *ptr;
1785         GList *tmp;
1786         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1787
1788         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1789         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1790
1791         if (info->app_info == NULL)
1792                 return PMINFO_R_ERROR;
1793
1794         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1795                 ptr = (icon_x *)tmp->data;
1796                 if (ptr == NULL || ptr->section == NULL)
1797                         continue;
1798
1799                 val = (char *)ptr->section;
1800                 if (val && strcmp(val, "setting") == 0) {
1801                         *icon = (char *)ptr->text;
1802                         return PMINFO_R_OK;
1803                 }
1804         }
1805
1806         return PMINFO_R_ERROR;
1807 }
1808
1809
1810 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1811 {
1812         char *val;
1813         icon_x *ptr;
1814         GList *tmp;
1815         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1816
1817         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1818         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1819
1820         if (info->app_info == NULL)
1821                 return PMINFO_R_ERROR;
1822
1823         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1824                 ptr = (icon_x *)tmp->data;
1825                 if (ptr == NULL || ptr->section == NULL)
1826                         continue;
1827
1828                 val = (char *)ptr->section;
1829                 if (val && strcmp(val, "notification") == 0){
1830                         *icon = (char *)ptr->text;
1831                         return PMINFO_R_OK;
1832                 }
1833         }
1834
1835         return PMINFO_R_ERROR;
1836 }
1837
1838 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1839 {
1840         char *val;
1841         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1842
1843         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1844         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1845
1846         if (info->app_info == NULL || info->app_info->recentimage == NULL)
1847                 return PMINFO_R_ERROR;
1848
1849         val = (char *)info->app_info->recentimage;
1850         if (strcasecmp(val, "capture") == 0)
1851                 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1852         else if (strcasecmp(val, "icon") == 0)
1853                 *type = PMINFO_RECENTIMAGE_USE_ICON;
1854         else
1855                 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1856
1857         return PMINFO_R_OK;
1858 }
1859
1860 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1861 {
1862         char *val;
1863         image_x *ptr;
1864         GList *tmp;
1865         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1866
1867         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1868         retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1869
1870         if (info->app_info == NULL)
1871                 return PMINFO_R_ERROR;
1872
1873         for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1874                 ptr = (image_x *)tmp->data;
1875                 if (ptr == NULL || ptr->section == NULL)
1876                         continue;
1877
1878                 val = (char *)ptr->section;
1879                 if (val && strcmp(val, "preview") == 0) {
1880                         *preview_img = (char *)ptr->text;
1881                         return PMINFO_R_OK;
1882                 }
1883         }
1884
1885         return PMINFO_R_ERROR;
1886 }
1887
1888 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1889 {
1890         const char *val;
1891         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1892
1893         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1894         retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1895
1896         val = info->app_info->permission_type;
1897         if (val == NULL)
1898                 return PMINFO_R_ERROR;
1899
1900         if (strcmp(val, "signature") == 0)
1901                 *permission = PMINFO_PERMISSION_SIGNATURE;
1902         else if (strcmp(val, "privilege") == 0)
1903                 *permission = PMINFO_PERMISSION_PRIVILEGE;
1904         else
1905                 *permission = PMINFO_PERMISSION_NORMAL;
1906
1907         return PMINFO_R_OK;
1908 }
1909
1910 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1911 {
1912         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1913
1914         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1915         retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1916
1917         if (info->app_info == NULL || info->app_info->component_type == NULL)
1918                 return PMINFO_R_ERROR;
1919
1920         *component_type = (char *)info->app_info->component_type;
1921
1922         return PMINFO_R_OK;
1923 }
1924
1925 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1926 {
1927         char *val;
1928         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1929
1930         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1931         retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1932
1933         if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1934                 return PMINFO_R_ERROR;
1935
1936         val = (char *)info->app_info->hwacceleration;
1937         if (strcasecmp(val, "not-use-GL") == 0)
1938                 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
1939         else if (strcasecmp(val, "use-GL") == 0)
1940                 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
1941         else
1942                 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
1943
1944         return PMINFO_R_OK;
1945 }
1946
1947 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1948 {
1949         char *val;
1950         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1951
1952         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1953         retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1954
1955         if (info->app_info == NULL || info->app_info->screenreader == NULL)
1956                 return PMINFO_R_ERROR;
1957
1958         val = (char *)info->app_info->screenreader;
1959         if (strcasecmp(val, "screenreader-off") == 0)
1960                 *screenreader = PMINFO_SCREENREADER_OFF;
1961         else if (strcasecmp(val, "screenreader-on") == 0)
1962                 *screenreader = PMINFO_SCREENREADER_ON;
1963         else
1964                 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1965
1966         return PMINFO_R_OK;
1967 }
1968
1969 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1970 {
1971         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1972
1973         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1974         retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1975         retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1976
1977         if (info->app_info == NULL || (info->app_info->portraitimg == NULL
1978                         && info->app_info->landscapeimg == NULL))
1979                 return PMINFO_R_ERROR;
1980
1981         *portrait_img = (char *)info->app_info->portraitimg;
1982         *landscape_img = (char *)info->app_info->landscapeimg;
1983
1984         return PMINFO_R_OK;
1985 }
1986
1987 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
1988 {
1989         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1990
1991         if (handle == NULL || effectimage_type == NULL) {
1992                 LOGE("invalid parameter");
1993                 return PMINFO_R_EINVAL;
1994         }
1995
1996         if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
1997                 return PMINFO_R_ERROR;
1998
1999         *effectimage_type = (char *)info->app_info->effectimage_type;
2000
2001         return PMINFO_R_OK;
2002 }
2003
2004 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h  handle, char **submode_mainid)
2005 {
2006         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2007
2008         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2009         retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2010
2011         if (info->app_info == NULL || info->app_info->submode_mainid == NULL)
2012                 return PMINFO_R_ERROR;
2013
2014         *submode_mainid = (char *)info->app_info->submode_mainid;
2015
2016         return PMINFO_R_OK;
2017 }
2018
2019 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
2020 {
2021         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2022         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2023
2024         if (info->app_info && info->app_info->installed_storage){
2025                  if (strcmp(info->app_info->installed_storage,"installed_internal") == 0)
2026                         *storage = PMINFO_INTERNAL_STORAGE;
2027                  else if (strcmp(info->app_info->installed_storage,"installed_external") == 0)
2028                          *storage = PMINFO_EXTERNAL_STORAGE;
2029                  else
2030                          return PMINFO_R_ERROR;
2031         }else
2032                 return PMINFO_R_ERROR;
2033
2034         return PMINFO_R_OK;
2035 }
2036
2037 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
2038 {
2039         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2040
2041         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2042         retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2043
2044         if (info->app_info->launch_mode == NULL)
2045                 return PMINFO_R_ERROR;
2046
2047         *mode = (char *)(info->app_info->launch_mode);
2048
2049         return PMINFO_R_OK;
2050 }
2051
2052 API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
2053 {
2054         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2055
2056         if (handle == NULL || alias_appid == NULL) {
2057                 LOGE("invalid parameter");
2058                 return PMINFO_R_EINVAL;
2059         }
2060
2061         if (info->app_info == NULL || info->app_info->alias_appid == NULL)
2062                 return PMINFO_R_ERROR;
2063
2064         *alias_appid = (char *)info->app_info->alias_appid;
2065
2066         return PMINFO_R_OK;
2067 }
2068
2069 API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
2070 {
2071         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2072
2073         if (handle == NULL || effective_appid == NULL) {
2074                 LOGE("invalid parameter");
2075                 return PMINFO_R_EINVAL;
2076         }
2077
2078         if (info->app_info == NULL || info->app_info->effective_appid == NULL)
2079                 return PMINFO_R_ERROR;
2080
2081         *effective_appid = (char *)info->app_info->effective_appid;
2082
2083         return PMINFO_R_OK;
2084 }
2085
2086 API int pkgmgrinfo_appinfo_get_tep_name(pkgmgrinfo_appinfo_h handle, char **tep_name)
2087 {
2088         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2089
2090         if (handle == NULL || tep_name == NULL) {
2091                 LOGE("invalid parameter");
2092                 return PMINFO_R_EINVAL;
2093         }
2094
2095         if (info->app_info == NULL || info->app_info->tep_name == NULL)
2096                 return PMINFO_R_ERROR;
2097
2098         *tep_name = (char *)info->app_info->tep_name;
2099
2100         return PMINFO_R_OK;
2101 }
2102
2103 API int pkgmgrinfo_appinfo_get_root_path(pkgmgrinfo_appinfo_h handle, char **root_path)
2104 {
2105         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2106
2107         if (handle == NULL || root_path == NULL) {
2108                 LOGE("invalid parameter");
2109                 return PMINFO_R_EINVAL;
2110         }
2111
2112         if (info->app_info == NULL || info->app_info->root_path == NULL)
2113                 return PMINFO_R_ERROR;
2114
2115         *root_path = (char *)info->app_info->root_path;
2116
2117         return PMINFO_R_OK;
2118 }
2119
2120 API int pkgmgrinfo_appinfo_get_api_version(pkgmgrinfo_appinfo_h handle, char **api_version)
2121 {
2122         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2123
2124         if (handle == NULL || api_version == NULL) {
2125                 LOGE("invalid parameter");
2126                 return PMINFO_R_EINVAL;
2127         }
2128
2129         if (info->app_info == NULL || info->app_info->api_version == NULL)
2130                 return PMINFO_R_ERROR;
2131
2132         *api_version = (char *)info->app_info->api_version;
2133
2134         return PMINFO_R_OK;
2135 }
2136
2137 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
2138 {
2139         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2140         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2141         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2142         retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2143
2144         int ret = PMINFO_R_OK;
2145         char *query = NULL;
2146         sqlite3_stmt *stmt = NULL;
2147
2148         /*open db*/
2149         ret = __open_manifest_db(uid, true);
2150         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2151
2152         /*Start constructing query*/
2153         query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
2154
2155         /*prepare query*/
2156         ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
2157         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
2158
2159         /*step query*/
2160         ret = sqlite3_step(stmt);
2161         tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
2162
2163         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2164         *access = strdup((char *)sqlite3_column_text(stmt, 2));
2165
2166         ret = PMINFO_R_OK;
2167
2168 catch:
2169         sqlite3_free(query);
2170         sqlite3_finalize(stmt);
2171         __close_manifest_db();
2172         return ret;
2173 }
2174
2175 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
2176 {
2177         return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
2178 }
2179
2180 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
2181 {
2182         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2183         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2184
2185         int ret = PMINFO_R_OK;
2186         char *query = NULL;
2187         sqlite3_stmt *stmt = NULL;
2188
2189         /*open db*/
2190         ret = __open_manifest_db(uid, true);
2191         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2192
2193         /*Start constructing query*/
2194         query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
2195
2196         /*prepare query*/
2197         ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
2198         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
2199
2200         /*step query*/
2201         ret = sqlite3_step(stmt);
2202         tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
2203
2204         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2205
2206         ret = PMINFO_R_OK;
2207
2208 catch:
2209         sqlite3_free(query);
2210         sqlite3_finalize(stmt);
2211         __close_manifest_db();
2212         return ret;
2213 }
2214
2215 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
2216 {
2217         return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
2218 }
2219
2220 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
2221                         pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
2222 {
2223         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2224         retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2225         int ret = -1;
2226         permission_x *ptr;
2227         GList *tmp;
2228         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2229
2230         if (info->app_info == NULL)
2231                 return PMINFO_R_ERROR;
2232
2233         for (tmp = info->app_info->permission; tmp; tmp = tmp->next) {
2234                 ptr = (permission_x *)tmp->data;
2235                 if (ptr == NULL)
2236                         continue;
2237                 if (ptr->value) {
2238                         ret = permission_func(ptr->value, user_data);
2239                         if (ret < 0)
2240                                 break;
2241                 }
2242         }
2243         return PMINFO_R_OK;
2244 }
2245
2246 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
2247                         pkgmgrinfo_app_category_list_cb category_func, void *user_data)
2248 {
2249         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2250         retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2251         int ret = -1;
2252         const char *category;
2253         GList *tmp;
2254         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2255
2256         if (info->app_info == NULL)
2257                 return PMINFO_R_ERROR;
2258
2259         for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2260                 category = (const char *)tmp->data;
2261                 if (category) {
2262                         ret = category_func(category, user_data);
2263                         if (ret < 0)
2264                                 break;
2265                 }
2266         }
2267         return PMINFO_R_OK;
2268 }
2269
2270 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
2271                         pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
2272 {
2273         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2274         retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2275         int ret = -1;
2276         metadata_x *ptr;
2277         GList *tmp;
2278         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2279
2280         if (info->app_info == NULL)
2281                 return PMINFO_R_ERROR;
2282
2283         for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
2284                 ptr = (metadata_x *)tmp->data;
2285                 if (ptr == NULL)
2286                         continue;
2287                 if (ptr->key) {
2288                         ret = metadata_func(ptr->key, ptr->value, user_data);
2289                         if (ret < 0)
2290                                 break;
2291                 }
2292         }
2293         return PMINFO_R_OK;
2294 }
2295
2296 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
2297                         pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
2298 {
2299         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2300         retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2301         int ret;
2302         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2303         appcontrol_x *appcontrol;
2304         GList *tmp;
2305
2306         if (info->app_info == NULL)
2307                 return PMINFO_R_ERROR;
2308
2309         for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2310                 appcontrol = (appcontrol_x *)tmp->data;
2311                 if (appcontrol == NULL)
2312                         continue;
2313                 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
2314                 if (ret < 0)
2315                         break;
2316         }
2317
2318         return PMINFO_R_OK;
2319 }
2320
2321 API int pkgmgrinfo_appinfo_foreach_background_category(
2322                 pkgmgrinfo_appinfo_h handle,
2323                 pkgmgrinfo_app_background_category_list_cb category_func,
2324                 void *user_data)
2325 {
2326         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2327         GList *tmp;
2328         char *category;
2329
2330         if (handle == NULL || category_func == NULL || info->app_info == NULL) {
2331                 LOGE("invalid parameter");
2332                 return PMINFO_R_EINVAL;
2333         }
2334
2335         for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
2336                 category = (char *)tmp->data;
2337                 if (category == NULL)
2338                         continue;
2339
2340                 if (category_func(category, user_data) < 0)
2341                         break;
2342         }
2343
2344         return PMINFO_R_OK;
2345 }
2346
2347 API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
2348                 pkgmgrinfo_app_splash_screen_list_cb splash_screen_func,
2349                 void *user_data)
2350 {
2351         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2352         splashscreen_x *splashscreen;
2353         GList *tmp;
2354         int ret;
2355
2356         if (info == NULL || info->app_info == NULL
2357                         || splash_screen_func == NULL) {
2358                 LOGE("invalid parameter");
2359                 return PMINFO_R_EINVAL;
2360         }
2361
2362         for (tmp = info->app_info->splashscreens; tmp; tmp = tmp->next) {
2363                 splashscreen = (splashscreen_x *)tmp->data;
2364                 if (splashscreen == NULL)
2365                         continue;
2366                 ret = splash_screen_func(splashscreen->src,
2367                                 splashscreen->type,
2368                                 splashscreen->orientation,
2369                                 splashscreen->indicatordisplay,
2370                                 splashscreen->operation,
2371                                 user_data);
2372                 if (ret < 0)
2373                         break;
2374         }
2375
2376         return PMINFO_R_OK;
2377 }
2378
2379 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
2380 {
2381         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2382         retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2383         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2384
2385         if (info->app_info == NULL || info->app_info->nodisplay == NULL)
2386                 return PMINFO_R_ERROR;
2387
2388         *nodisplay = _get_bool_value(info->app_info->nodisplay);
2389
2390         return PMINFO_R_OK;
2391 }
2392
2393 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
2394 {
2395         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2396         retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2397         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2398
2399         if (info->app_info == NULL || info->app_info->multiple == NULL)
2400                 return PMINFO_R_ERROR;
2401
2402         *multiple = _get_bool_value(info->app_info->multiple);
2403
2404         return PMINFO_R_OK;
2405 }
2406
2407 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
2408 {
2409         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2410         retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2411         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2412
2413         if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
2414                 return PMINFO_R_ERROR;
2415
2416         *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
2417
2418         return PMINFO_R_OK;
2419 }
2420
2421 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h  handle, bool *taskmanage)
2422 {
2423         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2424         retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2425         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2426
2427         if (info->app_info == NULL || info->app_info->taskmanage == NULL)
2428                 return PMINFO_R_ERROR;
2429
2430         *taskmanage = _get_bool_value(info->app_info->taskmanage);
2431
2432         return PMINFO_R_OK;
2433 }
2434
2435 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h  handle, bool *enabled)
2436 {
2437         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2438         retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2439         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2440
2441         if (info->app_info == NULL || info->app_info->enabled == NULL)
2442                 return PMINFO_R_ERROR;
2443
2444         *enabled = _get_bool_value(info->app_info->enabled);
2445
2446         return PMINFO_R_OK;
2447 }
2448
2449 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h  handle, bool *onboot)
2450 {
2451         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2452         retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2453         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2454
2455         if (info->app_info == NULL || info->app_info->onboot == NULL)
2456                 return PMINFO_R_ERROR;
2457
2458         *onboot = _get_bool_value(info->app_info->onboot);
2459
2460         return PMINFO_R_OK;
2461 }
2462
2463 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h  handle, bool *autorestart)
2464 {
2465         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2466         retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2467         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2468
2469         if (info->app_info == NULL || info->app_info->autorestart == NULL)
2470                 return PMINFO_R_ERROR;
2471
2472         *autorestart = _get_bool_value(info->app_info->autorestart);
2473
2474         return PMINFO_R_OK;
2475 }
2476
2477 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h  handle, bool *mainapp)
2478 {
2479         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2480         retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2481         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2482
2483         if (info->app_info == NULL || info->app_info->mainapp == NULL)
2484                 return PMINFO_R_ERROR;
2485
2486         *mainapp = _get_bool_value(info->app_info->mainapp);
2487
2488         return PMINFO_R_OK;
2489 }
2490
2491 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
2492 {
2493         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2494         retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2495         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2496
2497         if (info->app_info == NULL || info->app_info->preload == NULL)
2498                 return PMINFO_R_ERROR;
2499
2500         *preload = _get_bool_value(info->app_info->preload);
2501
2502         return PMINFO_R_OK;
2503 }
2504
2505 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
2506 {
2507         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2508         retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2509         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2510
2511         if (info->app_info == NULL || info->app_info->submode == NULL)
2512                 return PMINFO_R_ERROR;
2513
2514         *submode = _get_bool_value(info->app_info->submode);
2515
2516         return PMINFO_R_OK;
2517 }
2518
2519 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
2520 {
2521         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2522
2523         if (handle == NULL || process_pool == NULL) {
2524                 LOGE("invalid parameter");
2525                 return PMINFO_R_EINVAL;
2526         }
2527
2528         if (info->app_info == NULL)
2529                 return PMINFO_R_ERROR;
2530
2531         *process_pool = _get_bool_value(info->app_info->process_pool);
2532
2533         return PMINFO_R_OK;
2534 }
2535
2536 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
2537 {
2538         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2539         retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
2540         retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
2541
2542         const char *val;
2543         GList *tmp;
2544         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2545
2546         if (info->app_info == NULL)
2547                 return PMINFO_R_ERROR;
2548
2549         *exist = 0;
2550         for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2551                 val = (const char *)tmp->data;
2552                 if (val == NULL)
2553                         continue;
2554                 if (strcasecmp(val, category) == 0) {
2555                         *exist = 1;
2556                         break;
2557                 }
2558         }
2559
2560         return PMINFO_R_OK;
2561 }
2562
2563 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
2564                 bool *ui_gadget)
2565 {
2566         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2567
2568         if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
2569                 _LOGE("invalid parameter");
2570                 return PMINFO_R_EINVAL;
2571         }
2572
2573         *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
2574
2575         return PMINFO_R_OK;
2576 }
2577
2578 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
2579                 bool *support_disable)
2580 {
2581         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2582
2583         if (info == NULL || info->app_info == NULL || support_disable == NULL) {
2584                 _LOGE("invalid parameter");
2585                 return PMINFO_R_EINVAL;
2586         }
2587
2588         *support_disable = _get_bool_value(info->app_info->support_disable);
2589
2590         return PMINFO_R_OK;
2591 }
2592
2593 API int pkgmgrinfo_appinfo_is_disabled(pkgmgrinfo_appinfo_h handle, bool *disabled)
2594 {
2595         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2596         retvm_if(disabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2597         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2598
2599         if (info->app_info == NULL || info->app_info->is_disabled == NULL)
2600                 return PMINFO_R_ERROR;
2601
2602         *disabled = _get_bool_value(info->app_info->is_disabled);
2603
2604         return PMINFO_R_OK;
2605 }
2606
2607 API int pkgmgrinfo_appinfo_is_global(pkgmgrinfo_appinfo_h handle, bool *global)
2608 {
2609         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2610
2611         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2612         retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2613
2614         if (info->app_info == NULL || info->app_info->for_all_users == NULL)
2615                 return PMINFO_R_ERROR;
2616
2617         *global = _get_bool_value(info->app_info->for_all_users);
2618
2619         return PMINFO_R_OK;
2620
2621 }
2622
2623 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
2624 {
2625         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2626         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2627         __cleanup_appinfo(info);
2628         return PMINFO_R_OK;
2629 }
2630
2631 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
2632 {
2633         return (pkgmgrinfo_pkginfo_filter_create(handle));
2634 }
2635
2636 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
2637 {
2638         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2639 }
2640
2641 static gint __compare_func(gconstpointer data1, gconstpointer data2)
2642 {
2643         pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
2644         pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
2645         if (node1->prop == node2->prop)
2646                 return 0;
2647         else if (node1->prop > node2->prop)
2648                 return 1;
2649         else
2650                 return -1;
2651 }
2652
2653 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
2654                                 const char *property, const int value)
2655 {
2656         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2657         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2658         char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
2659         char *val = NULL;
2660         GSList *link = NULL;
2661         int prop = -1;
2662         prop = _pminfo_appinfo_convert_to_prop_int(property);
2663         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
2664                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
2665                 _LOGE("Invalid Integer Property\n");
2666                 return PMINFO_R_EINVAL;
2667         }
2668         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2669         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2670         if (node == NULL) {
2671                 _LOGE("Out of Memory!!!\n");
2672                 return PMINFO_R_ERROR;
2673         }
2674         snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
2675         val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
2676         if (val == NULL) {
2677                 _LOGE("Out of Memory\n");
2678                 free(node);
2679                 node = NULL;
2680                 return PMINFO_R_ERROR;
2681         }
2682         node->prop = prop;
2683         node->value = val;
2684         /*If API is called multiple times for same property, we should override the previous values.
2685         Last value set will be used for filtering.*/
2686         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2687         if (link)
2688                 filter->list = g_slist_delete_link(filter->list, link);
2689         filter->list = g_slist_append(filter->list, (gpointer)node);
2690         return PMINFO_R_OK;
2691
2692 }
2693
2694 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
2695                                 const char *property, const bool value)
2696 {
2697         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2698         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2699         char *val = NULL;
2700         GSList *link = NULL;
2701         int prop = -1;
2702         prop = _pminfo_appinfo_convert_to_prop_bool(property);
2703         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
2704                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
2705                 _LOGE("Invalid Boolean Property\n");
2706                 return PMINFO_R_EINVAL;
2707         }
2708         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2709         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2710         if (node == NULL) {
2711                 _LOGE("Out of Memory!!!\n");
2712                 return PMINFO_R_ERROR;
2713         }
2714         if (value)
2715                 val = strndup("('true','True')", 15);
2716         else
2717                 val = strndup("('false','False')", 17);
2718         if (val == NULL) {
2719                 _LOGE("Out of Memory\n");
2720                 free(node);
2721                 node = NULL;
2722                 return PMINFO_R_ERROR;
2723         }
2724         node->prop = prop;
2725         node->value = val;
2726         /*If API is called multiple times for same property, we should override the previous values.
2727         Last value set will be used for filtering.*/
2728         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2729         if (link)
2730                 filter->list = g_slist_delete_link(filter->list, link);
2731         filter->list = g_slist_append(filter->list, (gpointer)node);
2732         return PMINFO_R_OK;
2733
2734 }
2735
2736 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
2737                                 const char *property, const char *value)
2738 {
2739         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2740         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2741         retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2742         char *val = NULL;
2743         pkgmgrinfo_node_x *ptr = NULL;
2744         char prev[PKG_STRING_LEN_MAX] = {'\0'};
2745         char temp[PKG_STRING_LEN_MAX] = {'\0'};
2746         GSList *link = NULL;
2747         int prop = -1;
2748         prop = _pminfo_appinfo_convert_to_prop_str(property);
2749         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
2750                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
2751                 _LOGE("Invalid String Property\n");
2752                 return PMINFO_R_EINVAL;
2753         }
2754         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2755         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2756         if (node == NULL) {
2757                 _LOGE("Out of Memory!!!\n");
2758                 return PMINFO_R_ERROR;
2759         }
2760         node->prop = prop;
2761         switch (prop) {
2762         case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
2763                 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
2764                         val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
2765                 else
2766                         val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
2767                 node->value = val;
2768                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2769                 if (link)
2770                         filter->list = g_slist_delete_link(filter->list, link);
2771                 filter->list = g_slist_append(filter->list, (gpointer)node);
2772                 break;
2773         case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
2774         case E_PMINFO_APPINFO_PROP_APP_OPERATION:
2775         case E_PMINFO_APPINFO_PROP_APP_URI:
2776         case E_PMINFO_APPINFO_PROP_APP_MIME:
2777                 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
2778                 if (val == NULL) {
2779                         _LOGE("Out of Memory\n");
2780                         free(node);
2781                         node = NULL;
2782                         return PMINFO_R_ERROR;
2783                 }
2784                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2785                 if (link) {
2786                         ptr = (pkgmgrinfo_node_x *)link->data;
2787                         strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
2788                         _LOGE("Previous value is %s\n", prev);
2789                         filter->list = g_slist_delete_link(filter->list, link);
2790                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
2791                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
2792                         _LOGE("New value is %s\n", val);
2793                         node->value = val;
2794                         filter->list = g_slist_append(filter->list, (gpointer)node);
2795                         memset(temp, '\0', PKG_STRING_LEN_MAX);
2796                 } else {
2797                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
2798                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
2799                         _LOGE("First value is %s\n", val);
2800                         node->value = val;
2801                         filter->list = g_slist_append(filter->list, (gpointer)node);
2802                         memset(temp, '\0', PKG_STRING_LEN_MAX);
2803                 }
2804                 break;
2805         default:
2806                 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
2807                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2808                 if (link)
2809                         filter->list = g_slist_delete_link(filter->list, link);
2810                 filter->list = g_slist_append(filter->list, (gpointer)node);
2811                 break;
2812         }
2813         return PMINFO_R_OK;
2814 }
2815
2816 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
2817 {
2818         int ret;
2819         GList *list = NULL;
2820
2821         if (handle == NULL || count == NULL) {
2822                 _LOGE("invalid parameter");
2823                 return PMINFO_R_EINVAL;
2824         }
2825
2826         ret = _appinfo_get_filtered_list(handle, uid, &list);
2827         if (ret != PMINFO_R_OK)
2828                 return PMINFO_R_ERROR;
2829
2830         *count = g_list_length(list);
2831
2832         g_list_free_full(list, free);
2833
2834         return PMINFO_R_OK;
2835 }
2836
2837 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
2838 {
2839         return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
2840 }
2841
2842 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
2843                 pkgmgrinfo_appinfo_filter_h handle,
2844                 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2845 {
2846         if (handle == NULL || app_cb == NULL) {
2847                 LOGE("invalid parameter");
2848                 return PMINFO_R_EINVAL;
2849         }
2850
2851         return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2852                         user_data);
2853 }
2854
2855 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
2856                                 pkgmgrinfo_app_list_cb app_cb, void * user_data)
2857 {
2858         return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
2859 }
2860
2861 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
2862 {
2863         return (pkgmgrinfo_pkginfo_filter_create(handle));
2864 }
2865
2866 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
2867 {
2868         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2869 }
2870
2871 API int pkgmgrinfo_appinfo_metadata_filter_add(
2872                 pkgmgrinfo_appinfo_metadata_filter_h handle,
2873                 const char *key, const char *value)
2874 {
2875         int ret;
2876
2877         ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2878                         PMINFO_APPINFO_PROP_APP_METADATA_KEY, key);
2879         if (ret != PMINFO_R_OK)
2880                 return ret;
2881
2882         /* value can be NULL.
2883          * In that case all apps with specified key should be displayed
2884          */
2885         if (value) {
2886                 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2887                                 PMINFO_APPINFO_PROP_APP_METADATA_VALUE, value);
2888                 if (ret != PMINFO_R_OK)
2889                         return ret;
2890         }
2891
2892         return PMINFO_R_OK;
2893 }
2894
2895 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2896                 pkgmgrinfo_appinfo_metadata_filter_h handle,
2897                 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2898 {
2899         if (handle == NULL || app_cb == NULL) {
2900                 LOGE("invalid parameter");
2901                 return PMINFO_R_EINVAL;
2902         }
2903
2904         return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2905                         user_data);
2906 }
2907
2908 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
2909                 pkgmgrinfo_appinfo_metadata_filter_h handle,
2910                 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2911 {
2912         return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
2913                         user_data, GLOBAL_USER);
2914 }
2915
2916 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2917 {
2918         const char *val;
2919         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2920
2921         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2922         retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2923
2924         val = info->app_info->guestmode_visibility;
2925         *status = _get_bool_value(val);
2926         return PMINFO_R_OK;
2927 }