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