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