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