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