12 #include "pkgmgr-info.h"
13 #include "pkgmgrinfo_debug.h"
14 #include "pkgmgrinfo_private.h"
15 #include "pkgmgr_parser.h"
17 #define FILTER_QUERY_COUNT_APP "select count(DISTINCT package_app_info.app_id) " \
18 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
19 "ON package_app_info.app_id=package_app_localized_info.app_id " \
20 "and package_app_localized_info.app_locale='%s' " \
21 "LEFT OUTER JOIN package_app_app_svc " \
22 "ON package_app_info.app_id=package_app_app_svc.app_id " \
23 "LEFT OUTER JOIN package_app_app_category " \
24 "ON package_app_info.app_id=package_app_app_category.app_id where "
26 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
28 pkgmgr_appinfo_x *info = data;
29 pkgmgr_appinfo_x *tmp;
31 while (info != NULL) {
34 free((void *)info->package);
36 free((void *)info->locale);
38 pkgmgrinfo_basic_free_application(info->app_info);
45 static char *_get_filtered_query(const char *query_raw,
46 pkgmgrinfo_filter_x *filter)
48 char buf[MAX_QUERY_LEN] = { 0, };
57 strncat(buf, query_raw, MAX_QUERY_LEN - 1);
59 for (list = head; list; list = list->next) {
60 /* TODO: revise condition getter function */
61 __get_filter_condition(list->data, &condition);
62 if (condition == NULL)
64 if (buf[strlen(query_raw)] == '\0') {
65 len += strlen(" WHERE ");
66 strncat(buf, " WHERE ", MAX_QUERY_LEN - len - 1);
68 len += strlen(" AND ");
69 strncat(buf, " AND ", MAX_QUERY_LEN -len - 1);
71 len += strlen(condition);
72 strncat(buf, condition, sizeof(buf) - len - 1);
80 static GSList *_appinfo_get_filtered_list(const char *locale,
81 pkgmgrinfo_filter_x *filter)
83 static const char query_raw[] =
84 "SELECT package_app_info.app_id FROM package_app_info"
85 " LEFT OUTER JOIN package_app_localized_info"
86 " ON package_app_info.app_id=package_app_localized_info.app_id"
87 " AND package_app_localized_info.app_locale=%Q"
88 " LEFT OUTER JOIN package_app_app_category"
89 " ON package_app_info.app_id=package_app_app_category.app_id"
90 " LEFT OUTER JOIN package_app_app_svc"
91 " ON package_app_info.app_id=package_app_app_svc.app_id ";
94 char *query_localized;
99 query = _get_filtered_query(query_raw, filter);
102 query_localized = sqlite3_mprintf(query, locale);
104 if (query_localized == NULL)
107 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query_localized,
108 strlen(query_localized), &stmt, NULL);
109 sqlite3_free(query_localized);
110 if (ret != SQLITE_OK) {
111 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
115 while (sqlite3_step(stmt) == SQLITE_ROW) {
116 _save_column_str(stmt, 0, (const char **)&appid);
117 list = g_slist_append(list, appid);
120 sqlite3_finalize(stmt);
125 static int _appinfo_get_label(const char *appid, const char *locale,
128 static const char query_raw[] =
129 "SELECT app_label, app_locale "
130 "FROM package_app_localized_info "
131 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
138 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
140 LOGE("out of memory");
141 return PMINFO_R_ERROR;
144 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
147 if (ret != SQLITE_OK) {
148 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
149 return PMINFO_R_ERROR;
152 while (sqlite3_step(stmt) == SQLITE_ROW) {
153 info = calloc(1, sizeof(label_x));
155 LOGE("out of memory");
156 sqlite3_finalize(stmt);
158 LISTHEAD(*label, info);
161 return PMINFO_R_ERROR;
164 _save_column_str(stmt, idx++, &info->text);
165 _save_column_str(stmt, idx++, &info->lang);
166 LISTADD(*label, info);
170 LISTHEAD(*label, info);
174 sqlite3_finalize(stmt);
179 static int _appinfo_get_icon(const char *appid, const char *locale,
182 static const char query_raw[] =
183 "SELECT app_icon, app_locale "
184 "FROM package_app_localized_info "
185 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
192 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
194 LOGE("out of memory");
195 return PMINFO_R_ERROR;
198 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
201 if (ret != SQLITE_OK) {
202 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
203 return PMINFO_R_ERROR;
206 while (sqlite3_step(stmt) == SQLITE_ROW) {
207 info = calloc(1, sizeof(icon_x));
209 LOGE("out of memory");
210 sqlite3_finalize(stmt);
212 LISTHEAD(*icon, info);
215 return PMINFO_R_ERROR;
218 _save_column_str(stmt, idx++, &info->text);
219 _save_column_str(stmt, idx++, &info->lang);
220 LISTADD(*icon, info);
224 LISTHEAD(*icon, info);
228 sqlite3_finalize(stmt);
233 static int _appinfo_get_category(const char *appid, category_x **category)
235 static const char query_raw[] =
236 "SELECT category FROM package_app_app_category WHERE app_id=%Q";
242 query = sqlite3_mprintf(query_raw, appid);
244 LOGE("out of memory");
245 return PMINFO_R_ERROR;
248 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
251 if (ret != SQLITE_OK) {
252 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
253 return PMINFO_R_ERROR;
256 while (sqlite3_step(stmt) == SQLITE_ROW) {
257 info = calloc(1, sizeof(category_x));
259 LOGE("out of memory");
260 sqlite3_finalize(stmt);
262 LISTHEAD(*category, info);
265 return PMINFO_R_ERROR;
267 _save_column_str(stmt, 0, &info->name);
268 LISTADD(*category, info);
272 LISTHEAD(*category, info);
276 sqlite3_finalize(stmt);
281 static void __parse_appcontrol(appcontrol_x **appcontrol, char *appcontrol_str)
288 if (appcontrol_str == NULL)
291 dup = strdup(appcontrol_str);
293 ac = calloc(1, sizeof(appcontrol_x));
295 _LOGE("out of memory");
298 token = strtok_r(dup, "|", &ptr);
299 if (token && strcmp(token, "NULL"))
300 ac->operation = strdup(token);
301 token = strtok_r(NULL, "|", &ptr);
302 if (token && strcmp(token, "NULL"))
303 ac->uri = strdup(token);
304 token = strtok_r(NULL, "|", &ptr);
305 if (token && strcmp(token, "NULL"))
306 ac->mime = strdup(token);
307 LISTADD(*appcontrol, ac);
308 } while ((token = strtok_r(NULL, ";", &ptr)));
311 LISTHEAD(*appcontrol, ac);
317 static int _appinfo_get_app_control(const char *appid,
318 appcontrol_x **appcontrol)
320 static const char query_raw[] =
321 "SELECT app_control FROM package_app_app_control "
326 appcontrol_x *info = NULL;
329 query = sqlite3_mprintf(query_raw, appid);
331 LOGE("out of memory");
332 return PMINFO_R_ERROR;
335 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
338 if (ret != SQLITE_OK) {
339 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
340 return PMINFO_R_ERROR;
343 while (sqlite3_step(stmt) == SQLITE_ROW) {
345 _save_column_str(stmt, 0, (const char **)&str);
347 __parse_appcontrol(&info, str);
353 sqlite3_finalize(stmt);
358 static int _appinfo_get_data_control(const char *appid,
359 datacontrol_x **datacontrol)
361 static const char query_raw[] =
362 "SELECT providerid, access, type "
363 "FROM package_app_data_control WHERE app_id=%Q";
370 query = sqlite3_mprintf(query_raw, appid);
372 LOGE("out of memory");
373 return PMINFO_R_ERROR;
376 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
379 if (ret != SQLITE_OK) {
380 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
381 return PMINFO_R_ERROR;
384 while (sqlite3_step(stmt) == SQLITE_ROW) {
385 info = calloc(1, sizeof(datacontrol_x));
387 LOGE("out of memory");
388 sqlite3_finalize(stmt);
390 LISTHEAD(*datacontrol, info);
393 return PMINFO_R_ERROR;
396 _save_column_str(stmt, idx++, &info->providerid);
397 _save_column_str(stmt, idx++, &info->access);
398 _save_column_str(stmt, idx++, &info->type);
399 LISTADD(*datacontrol, info);
403 LISTHEAD(*datacontrol, info);
407 sqlite3_finalize(stmt);
412 static int _appinfo_get_app(const char *appid, const char *locale,
413 pkgmgr_appinfo_x **appinfo)
415 static const char query_raw[] =
416 "SELECT app_id, app_component, app_exec, app_nodisplay, "
417 "app_type, app_onboot, app_multiple, app_autorestart, "
418 "app_taskmanage, app_enabled, app_hwacceleration, "
419 "app_screenreader, app_mainapp, app_recentimage, "
420 "app_launchcondition, app_indicatordisplay, app_portraitimg, "
421 "app_landscapeimg, app_guestmodevisibility, "
422 "app_permissiontype, app_preload, app_submode, "
423 "app_submode_mainid, app_launch_mode, component_type, package "
424 "FROM package_app_info WHERE app_id=%Q";
429 pkgmgr_appinfo_x *info;
432 query = sqlite3_mprintf(query_raw, appid);
434 LOGE("out of memory");
435 return PMINFO_R_ERROR;
438 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
441 if (ret != SQLITE_OK) {
442 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
443 return PMINFO_R_ERROR;
446 ret = sqlite3_step(stmt);
447 if (ret == SQLITE_DONE) {
448 LOGE("cannot find app");
449 sqlite3_finalize(stmt);
450 return PMINFO_R_ENOENT;
451 } else if (ret != SQLITE_ROW) {
452 LOGE("step failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
453 sqlite3_finalize(stmt);
454 return PMINFO_R_ERROR;
457 app = calloc(1, sizeof(application_x));
459 LOGE("out of memory");
460 sqlite3_finalize(stmt);
461 return PMINFO_R_ERROR;
464 _save_column_str(stmt, idx++, &app->appid);
465 _save_column_str(stmt, idx++, &app->component);
466 _save_column_str(stmt, idx++, &app->exec);
467 _save_column_str(stmt, idx++, &app->nodisplay);
468 _save_column_str(stmt, idx++, &app->type);
469 _save_column_str(stmt, idx++, &app->onboot);
470 _save_column_str(stmt, idx++, &app->multiple);
471 _save_column_str(stmt, idx++, &app->autorestart);
472 _save_column_str(stmt, idx++, &app->taskmanage);
473 _save_column_str(stmt, idx++, &app->enabled);
474 _save_column_str(stmt, idx++, &app->hwacceleration);
475 _save_column_str(stmt, idx++, &app->screenreader);
476 _save_column_str(stmt, idx++, &app->mainapp);
477 _save_column_str(stmt, idx++, &app->recentimage);
478 _save_column_str(stmt, idx++, &app->launchcondition);
479 _save_column_str(stmt, idx++, &app->indicatordisplay);
480 _save_column_str(stmt, idx++, &app->portraitimg);
481 _save_column_str(stmt, idx++, &app->landscapeimg);
482 _save_column_str(stmt, idx++, &app->guestmode_visibility);
483 _save_column_str(stmt, idx++, &app->permission_type);
484 _save_column_str(stmt, idx++, &app->preload);
485 _save_column_str(stmt, idx++, &app->submode);
486 _save_column_str(stmt, idx++, &app->submode_mainid);
487 _save_column_str(stmt, idx++, &app->launch_mode);
488 _save_column_str(stmt, idx++, &app->component_type);
489 _save_column_str(stmt, idx++, &app->package);
491 if (_appinfo_get_label(app->appid, locale, &app->label)) {
492 pkgmgrinfo_basic_free_application(app);
493 sqlite3_finalize(stmt);
494 return PMINFO_R_ERROR;
497 if (_appinfo_get_icon(app->appid, locale, &app->icon)) {
498 pkgmgrinfo_basic_free_application(app);
499 sqlite3_finalize(stmt);
500 return PMINFO_R_ERROR;
503 if (_appinfo_get_category(app->appid, &app->category)) {
504 pkgmgrinfo_basic_free_application(app);
505 sqlite3_finalize(stmt);
506 return PMINFO_R_ERROR;
509 if (_appinfo_get_app_control(app->appid, &app->appcontrol)) {
510 pkgmgrinfo_basic_free_application(app);
511 sqlite3_finalize(stmt);
512 return PMINFO_R_ERROR;
515 if (_appinfo_get_data_control(app->appid, &app->datacontrol)) {
516 pkgmgrinfo_basic_free_application(app);
517 sqlite3_finalize(stmt);
518 return PMINFO_R_ERROR;
521 info = calloc(1, sizeof(pkgmgr_appinfo_x));
523 LOGE("out of memory");
524 pkgmgrinfo_basic_free_application(app);
525 sqlite3_finalize(stmt);
526 return PMINFO_R_ERROR;
529 info->package = strdup(app->package);
530 info->app_info = app;
531 info->locale = strdup(locale);
534 sqlite3_finalize(stmt);
539 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
540 pkgmgrinfo_appinfo_h *handle)
542 pkgmgr_appinfo_x *appinfo = NULL;
545 if (appid == NULL || handle == NULL) {
546 LOGE("invalid parameter");
547 return PMINFO_R_EINVAL;
550 if (__open_manifest_db(uid) < 0)
551 return PMINFO_R_ERROR;
553 locale = _get_system_locale();
554 if (locale == NULL) {
555 __close_manifest_db();
556 return PMINFO_R_ERROR;
559 if (_appinfo_get_app(appid, locale, &appinfo)) {
561 __close_manifest_db();
562 return PMINFO_R_ERROR;
568 __close_manifest_db();
573 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
575 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
578 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
579 pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb,
582 pkgmgr_appinfo_x *info;
589 if (__open_manifest_db(uid) < 0)
590 return PMINFO_R_ERROR;
592 locale = _get_system_locale();
593 if (locale == NULL) {
594 __close_manifest_db();
595 return PMINFO_R_ERROR;
598 list = _appinfo_get_filtered_list(locale, filter);
601 __close_manifest_db();
605 for (tmp = list; tmp; tmp = tmp->next) {
606 appid = (char *)tmp->data;
608 if (_appinfo_get_app(appid, locale, &info)) {
612 if (app_list_cb(info, user_data) < 0)
614 pkgmgrinfo_appinfo_destroy_appinfo(info);
621 __close_manifest_db();
626 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
627 pkgmgrinfo_app_component component,
628 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
631 pkgmgrinfo_appinfo_filter_h filter;
633 const char *comp_str = NULL;
635 if (handle == NULL || app_func == NULL) {
636 LOGE("invalied parameter");
637 return PMINFO_R_EINVAL;
640 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
641 LOGE("invalid parameter");
642 return PMINFO_R_EINVAL;
645 if (pkgmgrinfo_appinfo_filter_create(&filter))
646 return PMINFO_R_ERROR;
648 if (pkgmgrinfo_appinfo_filter_add_string(filter,
649 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
650 pkgmgrinfo_appinfo_filter_destroy(filter);
651 return PMINFO_R_ERROR;
657 comp_str = PMINFO_APPINFO_UI_APP;
660 comp_str = PMINFO_APPINFO_SVC_APP;
667 if (pkgmgrinfo_appinfo_filter_add_string(filter,
668 PMINFO_APPINFO_PROP_APP_COMPONENT,
670 pkgmgrinfo_appinfo_filter_destroy(filter);
671 return PMINFO_R_ERROR;
675 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, app_func,
678 pkgmgrinfo_appinfo_filter_destroy(filter);
683 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
684 pkgmgrinfo_app_list_cb app_func, void *user_data)
686 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
689 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
691 if (app_func == NULL) {
692 LOGE("invalid parameter");
693 return PMINFO_R_EINVAL;
696 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
700 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
702 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
705 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
707 if (app_func == NULL) {
708 LOGE("invalid parameter");
709 return PMINFO_R_EINVAL;
712 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
716 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
718 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
721 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
723 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
725 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
726 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
728 if (info->app_info == NULL || info->app_info->appid == NULL)
729 return PMINFO_R_ERROR;
730 *appid = (char *)info->app_info->appid;
735 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
737 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
739 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
740 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
742 if (info->package == NULL)
743 return PMINFO_R_ERROR;
745 *pkg_name = (char *)info->package;
750 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
752 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
754 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
755 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
757 if (info->package == NULL)
758 return PMINFO_R_ERROR;
760 *pkgid = (char *)info->package;
765 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
767 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
769 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
770 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
772 if (info->app_info == NULL || info->app_info->exec == NULL)
773 return PMINFO_R_ERROR;
774 *exec = (char *)info->app_info->exec;
780 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
785 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
787 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
788 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
790 locale = info->locale;
791 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
793 start = info->app_info->icon;
794 for (ptr = start; ptr != NULL; ptr = ptr->next) {
795 if (ptr->lang == NULL)
798 if (strcmp(ptr->lang, locale) == 0) {
799 *icon = (char *)ptr->text;
800 if (strcasecmp(*icon, "(null)") == 0) {
801 locale = DEFAULT_LOCALE;
806 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
807 *icon = (char *)ptr->text;
812 return PMINFO_R_ERROR;
816 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
821 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
823 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
824 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
826 locale = info->locale;
827 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
829 start = info->app_info->label;
830 for (ptr = start; ptr != NULL; ptr = ptr->next) {
831 if (ptr->lang == NULL)
834 if (strcmp(ptr->lang, locale) == 0) {
835 *label = (char *)ptr->text;
836 if (strcasecmp(*label, "(null)") == 0) {
837 locale = DEFAULT_LOCALE;
842 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
843 *label = (char *)ptr->text;
848 return PMINFO_R_ERROR;
851 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
855 sqlite3_stmt *stmt = NULL;
858 const char *manifest_db;
860 manifest_db = getUserPkgParserDBPathUID(uid);
861 if (manifest_db == NULL) {
862 _LOGE("Failed to get manifest db path");
866 if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
867 _LOGE("DB open fail\n");
871 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
873 _LOGE("Out of memory");
877 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
878 _LOGE("prepare_v2 fail\n");
882 if (sqlite3_step(stmt) == SQLITE_ROW) {
883 val = (char *)sqlite3_column_text(stmt, 0);
885 result = strdup(val);
889 sqlite3_finalize(stmt);
896 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
900 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
902 val = _get_localed_label(appid, locale, uid);
904 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
907 return PMINFO_R_ERROR;
914 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
916 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
919 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
921 if ( strcasecmp(comp, "uiapp") == 0)
922 return PMINFO_UI_APP;
923 else if ( strcasecmp(comp, "svcapp") == 0)
924 return PMINFO_SVC_APP;
929 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
931 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
934 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
935 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
937 if (info->app_info == NULL)
938 return PMINFO_R_ERROR;
940 comp = __appcomponent_convert(info->app_info->component);
942 return PMINFO_R_ERROR;
949 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
951 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
953 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
954 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
956 if (info->app_info == NULL || info->app_info->type == NULL)
957 return PMINFO_R_ERROR;
958 *app_type = (char *)info->app_info->type;
963 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
964 int *operation_count, char ***operation)
966 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
967 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
968 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
969 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
970 *operation_count = data->operation_count;
971 *operation = data->operation;
975 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
976 int *uri_count, char ***uri)
978 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
979 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
980 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
981 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
982 *uri_count = data->uri_count;
987 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
988 int *mime_count, char ***mime)
990 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
991 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
992 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
993 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
994 *mime_count = data->mime_count;
999 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1000 int *subapp_count, char ***subapp)
1002 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1003 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1004 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1005 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1006 *subapp_count = data->subapp_count;
1007 *subapp = data->subapp;
1011 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1015 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1017 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1018 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1020 for (ptr = info->app_info->icon; ptr != NULL; ptr = ptr->next) {
1021 if (ptr->section == NULL)
1024 val = (char *)ptr->section;
1025 if (val && strcmp(val, "setting") == 0) {
1026 *icon = (char *)ptr->text;
1031 return PMINFO_R_ERROR;
1035 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1039 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1041 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1042 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1044 for (ptr = info->app_info->icon; ptr != NULL; ptr = ptr->next) {
1045 if (ptr->section == NULL)
1048 val = (char *)ptr->section;
1049 if (val && strcmp(val, "notification") == 0){
1050 *icon = (char *)ptr->text;
1055 return PMINFO_R_ERROR;
1058 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1061 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1063 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1064 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1066 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1067 return PMINFO_R_ERROR;
1069 val = (char *)info->app_info->recentimage;
1070 if (strcasecmp(val, "capture") == 0)
1071 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1072 else if (strcasecmp(val, "icon") == 0)
1073 *type = PMINFO_RECENTIMAGE_USE_ICON;
1075 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1080 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1084 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1086 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1087 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1089 for (ptr = info->app_info->image; ptr != NULL; ptr = ptr->next) {
1090 if (ptr->section == NULL)
1093 val = (char *)ptr->section;
1094 if (val && strcmp(val, "preview") == 0) {
1095 *preview_img = (char *)ptr->text;
1100 return PMINFO_R_ERROR;
1103 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1106 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1108 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1109 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1111 val = info->app_info->permission_type;
1113 return PMINFO_R_ERROR;
1115 if (strcmp(val, "signature") == 0)
1116 *permission = PMINFO_PERMISSION_SIGNATURE;
1117 else if (strcmp(val, "privilege") == 0)
1118 *permission = PMINFO_PERMISSION_PRIVILEGE;
1120 *permission = PMINFO_PERMISSION_NORMAL;
1125 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1127 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1129 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1130 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1132 if (info->app_info == NULL || info->app_info->component_type == NULL)
1133 return PMINFO_R_ERROR;
1135 *component_type = (char *)info->app_info->component_type;
1140 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1143 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1145 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1146 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1148 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1149 return PMINFO_R_ERROR;
1151 val = (char *)info->app_info->hwacceleration;
1152 if (strcasecmp(val, "not-use-GL") == 0)
1153 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
1154 else if (strcasecmp(val, "use-GL") == 0)
1155 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
1157 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
1162 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1165 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1167 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1168 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1170 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1171 return PMINFO_R_ERROR;
1173 val = (char *)info->app_info->screenreader;
1174 if (strcasecmp(val, "screenreader-off") == 0)
1175 *screenreader = PMINFO_SCREENREADER_OFF;
1176 else if (strcasecmp(val, "screenreader-on") == 0)
1177 *screenreader = PMINFO_SCREENREADER_ON;
1179 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1184 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1186 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1188 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1189 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1190 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1192 if (info->app_info == NULL || info->app_info->portraitimg ||
1193 info->app_info->landscapeimg == NULL)
1194 return PMINFO_R_ERROR;
1196 *portrait_img = (char *)info->app_info->portraitimg;
1197 *landscape_img = (char *)info->app_info->landscapeimg;
1202 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
1204 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1206 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1207 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1209 if (info->app_info == NULL || info->app_info->submode_mainid == NULL)
1210 return PMINFO_R_ERROR;
1212 *submode_mainid = (char *)info->app_info->submode_mainid;
1217 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
1219 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1221 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1222 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1224 if (info->app_info->launch_mode == NULL)
1225 return PMINFO_R_ERROR;
1227 *mode = (char *)(info->app_info->launch_mode);
1232 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
1234 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1235 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1236 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1237 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1239 int ret = PMINFO_R_OK;
1241 sqlite3_stmt *stmt = NULL;
1244 ret = __open_manifest_db(uid);
1245 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1247 /*Start constructing query*/
1248 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
1251 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1252 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1255 ret = sqlite3_step(stmt);
1256 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1258 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1259 *access = strdup((char *)sqlite3_column_text(stmt, 2));
1264 sqlite3_free(query);
1265 sqlite3_finalize(stmt);
1266 __close_manifest_db();
1270 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
1272 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
1275 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
1277 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1278 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1280 int ret = PMINFO_R_OK;
1282 sqlite3_stmt *stmt = NULL;
1285 ret = __open_manifest_db(uid);
1286 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1288 /*Start constructing query*/
1289 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
1292 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1293 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1296 ret = sqlite3_step(stmt);
1297 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1299 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1304 sqlite3_free(query);
1305 sqlite3_finalize(stmt);
1306 __close_manifest_db();
1310 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1312 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
1315 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
1316 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
1318 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1319 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1321 permission_x *ptr = NULL;
1322 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1324 if (info->app_info == NULL)
1325 return PMINFO_R_ERROR;
1327 for (ptr = info->app_info->permission; ptr; ptr = ptr->next) {
1329 ret = permission_func(ptr->value, user_data);
1337 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
1338 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
1340 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1341 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1343 category_x *ptr = NULL;
1344 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1346 if (info->app_info == NULL)
1347 return PMINFO_R_ERROR;
1349 for (ptr = info->app_info->category; ptr; ptr = ptr->next) {
1351 ret = category_func(ptr->name, user_data);
1359 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
1360 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
1362 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1363 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1365 metadata_x *ptr = NULL;
1366 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1368 if (info->app_info == NULL)
1369 return PMINFO_R_ERROR;
1371 for (ptr = info->app_info->metadata; ptr; ptr = ptr->next) {
1373 ret = metadata_func(ptr->key, ptr->value, user_data);
1381 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
1382 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1384 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1385 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1387 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1388 appcontrol_x *appcontrol;
1390 if (info->uiapp_info == NULL)
1391 return PMINFO_R_ERROR;
1393 for (appcontrol = info->app_info->appcontrol; appcontrol; appcontrol = appcontrol->next) {
1394 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1402 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
1404 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1405 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1407 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1409 if (info->app_info == NULL)
1410 return PMINFO_R_ERROR;
1412 val = (char *)info->app_info->nodisplay;
1414 if (strcasecmp(val, "true") == 0)
1416 else if (strcasecmp(val, "false") == 0)
1424 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
1426 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1427 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1429 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1431 if (info->app_info == NULL)
1432 return PMINFO_R_ERROR;
1434 val = (char *)info->app_info->multiple;
1436 if (strcasecmp(val, "true") == 0)
1438 else if (strcasecmp(val, "false") == 0)
1446 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
1448 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1449 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1451 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1453 if (info->app_info == NULL)
1454 return PMINFO_R_ERROR;
1456 val = (char *)info->app_info->indicatordisplay;
1458 if (strcasecmp(val, "true") == 0){
1459 *indicator_disp = 1;
1460 }else if (strcasecmp(val, "false") == 0){
1461 *indicator_disp = 0;
1463 *indicator_disp = 0;
1469 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
1471 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1472 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1474 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1476 if (info->app_info == NULL)
1477 return PMINFO_R_ERROR;
1479 val = (char *)info->app_info->taskmanage;
1481 if (strcasecmp(val, "true") == 0)
1483 else if (strcasecmp(val, "false") == 0)
1491 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
1493 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1494 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1496 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1498 if (info->app_info == NULL)
1499 return PMINFO_R_ERROR;
1501 val = (char *)info->app_info->enabled;
1503 if (strcasecmp(val, "true") == 0)
1505 else if (strcasecmp(val, "false") == 0)
1514 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
1516 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1517 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1519 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1521 if (info->app_info == NULL)
1522 return PMINFO_R_ERROR;
1524 val = (char *)info->app_info->onboot;
1526 if (strcasecmp(val, "true") == 0)
1528 else if (strcasecmp(val, "false") == 0)
1536 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
1538 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1539 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1541 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1543 if (info->app_info == NULL)
1544 return PMINFO_R_ERROR;
1546 val = (char *)info->app_info->autorestart;
1548 if (strcasecmp(val, "true") == 0)
1550 else if (strcasecmp(val, "false") == 0)
1558 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
1560 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1561 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1563 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1565 if (info->app_info == NULL)
1566 return PMINFO_R_ERROR;
1568 val = (char *)info->app_info->mainapp;
1570 if (strcasecmp(val, "true") == 0)
1572 else if (strcasecmp(val, "false") == 0)
1580 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
1582 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1583 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1585 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1587 if (info->app_info == NULL)
1588 return PMINFO_R_ERROR;
1590 val = (char *)info->app_info->preload;
1592 if (strcasecmp(val, "true") == 0)
1594 else if (strcasecmp(val, "false") == 0)
1602 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
1604 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1605 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1607 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1609 if (info->app_info == NULL)
1610 return PMINFO_R_ERROR;
1612 val = (char *)info->app_info->submode;
1614 if (strcasecmp(val, "true") == 0)
1616 else if (strcasecmp(val, "false") == 0)
1624 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
1626 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1627 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
1628 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
1630 category_x *ptr = NULL;
1631 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1633 if (info->app_info == NULL)
1634 return PMINFO_R_ERROR;
1637 for (ptr = info->app_info->category; ptr; ptr = ptr->next) {
1639 if (strcasecmp(ptr->name, category) == 0) {
1649 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
1651 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1652 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1653 __cleanup_appinfo(info);
1657 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
1659 return (pkgmgrinfo_pkginfo_filter_create(handle));
1662 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
1664 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1667 static gint __compare_func(gconstpointer data1, gconstpointer data2)
1669 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
1670 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
1671 if (node1->prop == node2->prop)
1673 else if (node1->prop > node2->prop)
1679 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
1680 const char *property, const int value)
1682 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1683 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1684 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1686 GSList *link = NULL;
1688 prop = _pminfo_appinfo_convert_to_prop_int(property);
1689 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
1690 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
1691 _LOGE("Invalid Integer Property\n");
1692 return PMINFO_R_EINVAL;
1694 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1695 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1697 _LOGE("Out of Memory!!!\n");
1698 return PMINFO_R_ERROR;
1700 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1701 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1703 _LOGE("Out of Memory\n");
1706 return PMINFO_R_ERROR;
1710 /*If API is called multiple times for same property, we should override the previous values.
1711 Last value set will be used for filtering.*/
1712 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1714 filter->list = g_slist_delete_link(filter->list, link);
1715 filter->list = g_slist_append(filter->list, (gpointer)node);
1720 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
1721 const char *property, const bool value)
1723 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1724 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1726 GSList *link = NULL;
1728 prop = _pminfo_appinfo_convert_to_prop_bool(property);
1729 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
1730 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
1731 _LOGE("Invalid Boolean Property\n");
1732 return PMINFO_R_EINVAL;
1734 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1735 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1737 _LOGE("Out of Memory!!!\n");
1738 return PMINFO_R_ERROR;
1741 val = strndup("('true','True')", 15);
1743 val = strndup("('false','False')", 17);
1745 _LOGE("Out of Memory\n");
1748 return PMINFO_R_ERROR;
1752 /*If API is called multiple times for same property, we should override the previous values.
1753 Last value set will be used for filtering.*/
1754 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1756 filter->list = g_slist_delete_link(filter->list, link);
1757 filter->list = g_slist_append(filter->list, (gpointer)node);
1762 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
1763 const char *property, const char *value)
1765 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1766 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1767 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1769 pkgmgrinfo_node_x *ptr = NULL;
1770 char prev[PKG_STRING_LEN_MAX] = {'\0'};
1771 char temp[PKG_STRING_LEN_MAX] = {'\0'};
1772 GSList *link = NULL;
1774 prop = _pminfo_appinfo_convert_to_prop_str(property);
1775 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
1776 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
1777 _LOGE("Invalid String Property\n");
1778 return PMINFO_R_EINVAL;
1780 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1781 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1783 _LOGE("Out of Memory!!!\n");
1784 return PMINFO_R_ERROR;
1788 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
1789 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
1790 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
1792 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
1794 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1796 filter->list = g_slist_delete_link(filter->list, link);
1797 filter->list = g_slist_append(filter->list, (gpointer)node);
1799 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
1800 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
1801 case E_PMINFO_APPINFO_PROP_APP_URI:
1802 case E_PMINFO_APPINFO_PROP_APP_MIME:
1803 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
1805 _LOGE("Out of Memory\n");
1808 return PMINFO_R_ERROR;
1810 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1812 ptr = (pkgmgrinfo_node_x *)link->data;
1813 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
1814 _LOGE("Previous value is %s\n", prev);
1815 filter->list = g_slist_delete_link(filter->list, link);
1816 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
1817 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1818 _LOGE("New value is %s\n", val);
1820 filter->list = g_slist_append(filter->list, (gpointer)node);
1821 memset(temp, '\0', PKG_STRING_LEN_MAX);
1823 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
1824 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1825 _LOGE("First value is %s\n", val);
1827 filter->list = g_slist_append(filter->list, (gpointer)node);
1828 memset(temp, '\0', PKG_STRING_LEN_MAX);
1832 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
1833 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1835 filter->list = g_slist_delete_link(filter->list, link);
1836 filter->list = g_slist_append(filter->list, (gpointer)node);
1842 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
1844 int *p = (int*)data;
1845 *p = atoi(coltxt[0]);
1846 _LOGE("count value is %d\n", *p);
1850 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
1852 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1853 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1854 char *locale = NULL;
1855 char *condition = NULL;
1856 char *error_message = NULL;
1857 char query[MAX_QUERY_LEN] = {'\0'};
1858 char where[MAX_QUERY_LEN] = {'\0'};
1862 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1863 /*Get current locale*/
1864 locale = _get_system_locale();
1865 if (locale == NULL) {
1866 _LOGE("manifest locale is NULL\n");
1867 return PMINFO_R_ERROR;
1870 ret = __open_manifest_db(uid);
1872 _LOGE("Fail to open manifest DB\n");
1874 return PMINFO_R_ERROR;
1877 /*Start constructing query*/
1878 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
1880 /*Get where clause*/
1881 for (list = filter->list; list; list = g_slist_next(list)) {
1882 __get_filter_condition(list->data, &condition);
1884 strncat(where, condition, sizeof(where) - strlen(where) -1);
1885 where[sizeof(where) - 1] = '\0';
1889 if (g_slist_next(list)) {
1890 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
1891 where[sizeof(where) - 1] = '\0';
1894 if (strlen(where) > 0) {
1895 strncat(query, where, sizeof(query) - strlen(query) - 1);
1896 query[sizeof(query) - 1] = '\0';
1901 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
1902 _LOGE("Don't execute query = %s error message = %s\n", query,
1904 sqlite3_free(error_message);
1905 ret = PMINFO_R_ERROR;
1915 __close_manifest_db();
1919 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
1921 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
1924 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
1925 pkgmgrinfo_appinfo_filter_h handle,
1926 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
1928 if (handle == NULL || app_cb == NULL) {
1929 LOGE("invalid parameter");
1930 return PMINFO_R_EINVAL;
1933 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
1937 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
1938 pkgmgrinfo_app_list_cb app_cb, void * user_data)
1940 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
1943 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
1945 return (pkgmgrinfo_pkginfo_filter_create(handle));
1948 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
1950 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1953 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
1954 const char *key, const char *value)
1956 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
1957 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
1958 /*value can be NULL. In that case all apps with specified key should be displayed*/
1962 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1963 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1964 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
1966 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
1970 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
1973 /*If API is called multiple times, we should OR all conditions.*/
1974 filter->list = g_slist_append(filter->list, (gpointer)node);
1975 /*All memory will be freed in destroy API*/
1993 static void __get_metadata_filter_condition(gpointer data, char **condition)
1995 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
1996 char key[MAX_QUERY_LEN] = {'\0'};
1997 char value[MAX_QUERY_LEN] = {'\0'};
1999 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
2002 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
2007 *condition = strdup(key);
2011 static char *_get_metadata_filtered_query(const char *query_raw,
2012 pkgmgrinfo_filter_x *filter)
2014 char buf[MAX_QUERY_LEN] = { 0, };
2018 GSList *head = NULL;
2021 head = filter->list;
2023 strncat(buf, query_raw, MAX_QUERY_LEN - 1);
2025 for (list = head; list; list = list->next) {
2026 /* TODO: revise condition getter function */
2027 __get_metadata_filter_condition(list->data, &condition);
2028 if (condition == NULL)
2030 if (buf[strlen(query_raw)] == '\0') {
2031 len += strlen(" WHERE ");
2032 strncat(buf, " WHERE ", MAX_QUERY_LEN - len - 1);
2034 len += strlen(" AND ");
2035 strncat(buf, " AND ", MAX_QUERY_LEN -len - 1);
2037 len += strlen(condition);
2038 strncat(buf, condition, sizeof(buf) - len - 1);
2046 static GSList *_appinfo_get_metadata_filtered_list(pkgmgrinfo_filter_x *filter)
2048 static const char query_raw[] =
2049 "SELECT app_id FROM package_app_app_metadata";
2053 GSList *list = NULL;
2056 query = _get_metadata_filtered_query(query_raw, filter);
2057 if (query == NULL) {
2058 LOGE("out of memory");
2062 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
2065 if (ret != SQLITE_OK) {
2066 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
2070 while (sqlite3_step(stmt) == SQLITE_ROW) {
2071 _save_column_str(stmt, 0, (const char **)&appid);
2072 list = g_slist_append(list, appid);
2075 sqlite3_finalize(stmt);
2080 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2081 pkgmgrinfo_appinfo_metadata_filter_h handle,
2082 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2087 pkgmgrinfo_appinfo_h info;
2090 if (handle == NULL || app_cb == NULL) {
2091 LOGE("invalid parameter");
2092 return PMINFO_R_EINVAL;
2095 if (__open_manifest_db(uid) < 0)
2096 return PMINFO_R_ERROR;
2098 list = _appinfo_get_metadata_filtered_list(handle);
2101 __close_manifest_db();
2105 for (tmp = list; tmp; tmp = tmp->next) {
2106 appid = (char *)tmp->data;
2108 if (pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid,
2113 if (app_cb(info, user_data) < 0)
2115 pkgmgrinfo_appinfo_destroy_appinfo(info);
2121 __close_manifest_db();
2126 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
2127 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2129 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, user_data, GLOBAL_USER);
2132 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2135 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2137 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2138 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2140 val = info->uiapp_info->guestmode_visibility;
2142 if (strcasecmp(val, "true") == 0){
2144 }else if (strcasecmp(val, "false") == 0){