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