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