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