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