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