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