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