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