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 bool _get_bool_value(const char *str)
30 else if (!strcasecmp(str, "true"))
36 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
38 pkgmgr_appinfo_x *info = data;
39 pkgmgr_appinfo_x *tmp;
41 while (info != NULL) {
44 free((void *)info->package);
46 free((void *)info->locale);
48 pkgmgrinfo_basic_free_application(info->app_info);
55 static char *_get_filtered_query(const char *query_raw,
56 pkgmgrinfo_filter_x *filter)
58 char buf[MAX_QUERY_LEN] = { 0, };
67 strncat(buf, query_raw, MAX_QUERY_LEN - 1);
69 for (list = head; list; list = list->next) {
70 /* TODO: revise condition getter function */
71 __get_filter_condition(list->data, &condition);
72 if (condition == NULL)
74 if (buf[strlen(query_raw)] == '\0') {
75 len += strlen(" WHERE ");
76 strncat(buf, " WHERE ", MAX_QUERY_LEN - len - 1);
78 len += strlen(" AND ");
79 strncat(buf, " AND ", MAX_QUERY_LEN -len - 1);
81 len += strlen(condition);
82 strncat(buf, condition, sizeof(buf) - len - 1);
90 static GSList *_appinfo_get_filtered_list(const char *locale,
91 pkgmgrinfo_filter_x *filter)
93 static const char query_raw[] =
94 "SELECT DISTINCT package_app_info.app_id FROM package_app_info"
95 " LEFT OUTER JOIN package_app_localized_info"
96 " ON package_app_info.app_id=package_app_localized_info.app_id"
97 " AND package_app_localized_info.app_locale=%Q"
98 " LEFT OUTER JOIN package_app_app_category"
99 " ON package_app_info.app_id=package_app_app_category.app_id"
100 " LEFT OUTER JOIN package_app_app_svc"
101 " ON package_app_info.app_id=package_app_app_svc.app_id ";
104 char *query_localized;
109 query = _get_filtered_query(query_raw, filter);
112 query_localized = sqlite3_mprintf(query, locale);
114 if (query_localized == NULL)
117 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query_localized,
118 strlen(query_localized), &stmt, NULL);
119 sqlite3_free(query_localized);
120 if (ret != SQLITE_OK) {
121 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
125 while (sqlite3_step(stmt) == SQLITE_ROW) {
126 _save_column_str(stmt, 0, (const char **)&appid);
127 list = g_slist_append(list, appid);
130 sqlite3_finalize(stmt);
135 static int _appinfo_get_label(const char *appid, const char *locale,
138 static const char query_raw[] =
139 "SELECT app_label, app_locale "
140 "FROM package_app_localized_info "
141 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
148 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
150 LOGE("out of memory");
151 return PMINFO_R_ERROR;
154 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
157 if (ret != SQLITE_OK) {
158 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
159 return PMINFO_R_ERROR;
162 while (sqlite3_step(stmt) == SQLITE_ROW) {
163 info = calloc(1, sizeof(label_x));
165 LOGE("out of memory");
166 sqlite3_finalize(stmt);
168 LISTHEAD(*label, info);
171 return PMINFO_R_ERROR;
174 _save_column_str(stmt, idx++, &info->text);
175 _save_column_str(stmt, idx++, &info->lang);
176 LISTADD(*label, info);
180 LISTHEAD(*label, info);
184 sqlite3_finalize(stmt);
189 static int _appinfo_get_icon(const char *appid, const char *locale,
192 static const char query_raw[] =
193 "SELECT app_icon, app_locale "
194 "FROM package_app_localized_info "
195 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
202 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
204 LOGE("out of memory");
205 return PMINFO_R_ERROR;
208 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
211 if (ret != SQLITE_OK) {
212 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
213 return PMINFO_R_ERROR;
216 while (sqlite3_step(stmt) == SQLITE_ROW) {
217 info = calloc(1, sizeof(icon_x));
219 LOGE("out of memory");
220 sqlite3_finalize(stmt);
222 LISTHEAD(*icon, info);
225 return PMINFO_R_ERROR;
228 _save_column_str(stmt, idx++, &info->text);
229 _save_column_str(stmt, idx++, &info->lang);
230 LISTADD(*icon, info);
234 LISTHEAD(*icon, info);
238 sqlite3_finalize(stmt);
243 static int _appinfo_get_category(const char *appid, category_x **category)
245 static const char query_raw[] =
246 "SELECT category FROM package_app_app_category WHERE app_id=%Q";
252 query = sqlite3_mprintf(query_raw, appid);
254 LOGE("out of memory");
255 return PMINFO_R_ERROR;
258 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
261 if (ret != SQLITE_OK) {
262 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
263 return PMINFO_R_ERROR;
266 while (sqlite3_step(stmt) == SQLITE_ROW) {
267 info = calloc(1, sizeof(category_x));
269 LOGE("out of memory");
270 sqlite3_finalize(stmt);
272 LISTHEAD(*category, info);
275 return PMINFO_R_ERROR;
277 _save_column_str(stmt, 0, &info->name);
278 LISTADD(*category, info);
282 LISTHEAD(*category, info);
286 sqlite3_finalize(stmt);
291 static void __parse_appcontrol(appcontrol_x **appcontrol, char *appcontrol_str)
298 if (appcontrol_str == NULL)
301 dup = strdup(appcontrol_str);
303 ac = calloc(1, sizeof(appcontrol_x));
305 _LOGE("out of memory");
308 token = strtok_r(dup, "|", &ptr);
309 if (token && strcmp(token, "NULL"))
310 ac->operation = strdup(token);
311 token = strtok_r(NULL, "|", &ptr);
312 if (token && strcmp(token, "NULL"))
313 ac->uri = strdup(token);
314 token = strtok_r(NULL, "|", &ptr);
315 if (token && strcmp(token, "NULL"))
316 ac->mime = strdup(token);
317 LISTADD(*appcontrol, ac);
318 } while ((token = strtok_r(NULL, ";", &ptr)));
321 LISTHEAD(*appcontrol, ac);
327 static int _appinfo_get_app_control(const char *appid,
328 appcontrol_x **appcontrol)
330 static const char query_raw[] =
331 "SELECT app_control FROM package_app_app_control "
336 appcontrol_x *info = NULL;
339 query = sqlite3_mprintf(query_raw, appid);
341 LOGE("out of memory");
342 return PMINFO_R_ERROR;
345 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
348 if (ret != SQLITE_OK) {
349 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
350 return PMINFO_R_ERROR;
353 while (sqlite3_step(stmt) == SQLITE_ROW) {
355 _save_column_str(stmt, 0, (const char **)&str);
357 __parse_appcontrol(&info, str);
363 sqlite3_finalize(stmt);
368 static int _appinfo_get_data_control(const char *appid,
369 datacontrol_x **datacontrol)
371 static const char query_raw[] =
372 "SELECT providerid, access, type "
373 "FROM package_app_data_control WHERE app_id=%Q";
380 query = sqlite3_mprintf(query_raw, appid);
382 LOGE("out of memory");
383 return PMINFO_R_ERROR;
386 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
389 if (ret != SQLITE_OK) {
390 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
391 return PMINFO_R_ERROR;
394 while (sqlite3_step(stmt) == SQLITE_ROW) {
395 info = calloc(1, sizeof(datacontrol_x));
397 LOGE("out of memory");
398 sqlite3_finalize(stmt);
400 LISTHEAD(*datacontrol, info);
403 return PMINFO_R_ERROR;
406 _save_column_str(stmt, idx++, &info->providerid);
407 _save_column_str(stmt, idx++, &info->access);
408 _save_column_str(stmt, idx++, &info->type);
409 LISTADD(*datacontrol, info);
413 LISTHEAD(*datacontrol, info);
417 sqlite3_finalize(stmt);
422 static int _appinfo_get_app(const char *appid, const char *locale,
423 pkgmgr_appinfo_x **appinfo)
425 static const char query_raw[] =
426 "SELECT app_id, app_component, app_exec, app_nodisplay, "
427 "app_type, app_onboot, app_multiple, app_autorestart, "
428 "app_taskmanage, app_enabled, app_hwacceleration, "
429 "app_screenreader, app_mainapp, app_recentimage, "
430 "app_launchcondition, app_indicatordisplay, app_portraitimg, "
431 "app_landscapeimg, app_guestmodevisibility, "
432 "app_permissiontype, app_preload, app_submode, "
433 "app_submode_mainid, app_launch_mode, app_ui_gadget, "
434 "component_type, package "
435 "FROM package_app_info WHERE app_id=%Q";
440 pkgmgr_appinfo_x *info;
443 query = sqlite3_mprintf(query_raw, appid);
445 LOGE("out of memory");
446 return PMINFO_R_ERROR;
449 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
452 if (ret != SQLITE_OK) {
453 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
454 return PMINFO_R_ERROR;
457 ret = sqlite3_step(stmt);
458 if (ret == SQLITE_DONE) {
459 LOGE("cannot find app");
460 sqlite3_finalize(stmt);
461 return PMINFO_R_ENOENT;
462 } else if (ret != SQLITE_ROW) {
463 LOGE("step failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
464 sqlite3_finalize(stmt);
465 return PMINFO_R_ERROR;
468 app = calloc(1, sizeof(application_x));
470 LOGE("out of memory");
471 sqlite3_finalize(stmt);
472 return PMINFO_R_ERROR;
475 _save_column_str(stmt, idx++, &app->appid);
476 _save_column_str(stmt, idx++, &app->component);
477 _save_column_str(stmt, idx++, &app->exec);
478 _save_column_str(stmt, idx++, &app->nodisplay);
479 _save_column_str(stmt, idx++, &app->type);
480 _save_column_str(stmt, idx++, &app->onboot);
481 _save_column_str(stmt, idx++, &app->multiple);
482 _save_column_str(stmt, idx++, &app->autorestart);
483 _save_column_str(stmt, idx++, &app->taskmanage);
484 _save_column_str(stmt, idx++, &app->enabled);
485 _save_column_str(stmt, idx++, &app->hwacceleration);
486 _save_column_str(stmt, idx++, &app->screenreader);
487 _save_column_str(stmt, idx++, &app->mainapp);
488 _save_column_str(stmt, idx++, &app->recentimage);
489 _save_column_str(stmt, idx++, &app->launchcondition);
490 _save_column_str(stmt, idx++, &app->indicatordisplay);
491 _save_column_str(stmt, idx++, &app->portraitimg);
492 _save_column_str(stmt, idx++, &app->landscapeimg);
493 _save_column_str(stmt, idx++, &app->guestmode_visibility);
494 _save_column_str(stmt, idx++, &app->permission_type);
495 _save_column_str(stmt, idx++, &app->preload);
496 _save_column_str(stmt, idx++, &app->submode);
497 _save_column_str(stmt, idx++, &app->submode_mainid);
498 _save_column_str(stmt, idx++, &app->launch_mode);
499 _save_column_str(stmt, idx++, &app->ui_gadget);
500 _save_column_str(stmt, idx++, &app->component_type);
501 _save_column_str(stmt, idx++, &app->package);
503 if (_appinfo_get_label(app->appid, locale, &app->label)) {
504 pkgmgrinfo_basic_free_application(app);
505 sqlite3_finalize(stmt);
506 return PMINFO_R_ERROR;
509 if (_appinfo_get_icon(app->appid, locale, &app->icon)) {
510 pkgmgrinfo_basic_free_application(app);
511 sqlite3_finalize(stmt);
512 return PMINFO_R_ERROR;
515 if (_appinfo_get_category(app->appid, &app->category)) {
516 pkgmgrinfo_basic_free_application(app);
517 sqlite3_finalize(stmt);
518 return PMINFO_R_ERROR;
521 if (_appinfo_get_app_control(app->appid, &app->appcontrol)) {
522 pkgmgrinfo_basic_free_application(app);
523 sqlite3_finalize(stmt);
524 return PMINFO_R_ERROR;
527 if (_appinfo_get_data_control(app->appid, &app->datacontrol)) {
528 pkgmgrinfo_basic_free_application(app);
529 sqlite3_finalize(stmt);
530 return PMINFO_R_ERROR;
533 info = calloc(1, sizeof(pkgmgr_appinfo_x));
535 LOGE("out of memory");
536 pkgmgrinfo_basic_free_application(app);
537 sqlite3_finalize(stmt);
538 return PMINFO_R_ERROR;
541 info->package = strdup(app->package);
542 info->app_info = app;
543 info->locale = strdup(locale);
546 sqlite3_finalize(stmt);
551 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
552 pkgmgrinfo_appinfo_h *handle)
554 pkgmgr_appinfo_x *appinfo = NULL;
557 if (appid == NULL || handle == NULL) {
558 LOGE("invalid parameter");
559 return PMINFO_R_EINVAL;
562 if (__open_manifest_db(uid) < 0)
563 return PMINFO_R_ERROR;
565 locale = _get_system_locale();
566 if (locale == NULL) {
567 __close_manifest_db();
568 return PMINFO_R_ERROR;
571 if (_appinfo_get_app(appid, locale, &appinfo)) {
573 __close_manifest_db();
574 return PMINFO_R_ERROR;
580 __close_manifest_db();
585 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
587 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
590 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
591 pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb,
594 pkgmgr_appinfo_x *info;
601 if (__open_manifest_db(uid) < 0)
602 return PMINFO_R_ERROR;
604 locale = _get_system_locale();
605 if (locale == NULL) {
606 __close_manifest_db();
607 return PMINFO_R_ERROR;
610 list = _appinfo_get_filtered_list(locale, filter);
613 __close_manifest_db();
617 for (tmp = list; tmp; tmp = tmp->next) {
618 appid = (char *)tmp->data;
620 if (_appinfo_get_app(appid, locale, &info)) {
624 if (app_list_cb(info, user_data) < 0)
626 pkgmgrinfo_appinfo_destroy_appinfo(info);
633 __close_manifest_db();
638 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
639 pkgmgrinfo_app_component component,
640 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
643 pkgmgrinfo_appinfo_filter_h filter;
645 const char *comp_str = NULL;
647 if (handle == NULL || app_func == NULL) {
648 LOGE("invalied parameter");
649 return PMINFO_R_EINVAL;
652 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
653 LOGE("invalid parameter");
654 return PMINFO_R_EINVAL;
657 if (pkgmgrinfo_appinfo_filter_create(&filter))
658 return PMINFO_R_ERROR;
660 if (pkgmgrinfo_appinfo_filter_add_string(filter,
661 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
662 pkgmgrinfo_appinfo_filter_destroy(filter);
663 return PMINFO_R_ERROR;
669 comp_str = PMINFO_APPINFO_UI_APP;
672 comp_str = PMINFO_APPINFO_SVC_APP;
679 if (pkgmgrinfo_appinfo_filter_add_string(filter,
680 PMINFO_APPINFO_PROP_APP_COMPONENT,
682 pkgmgrinfo_appinfo_filter_destroy(filter);
683 return PMINFO_R_ERROR;
687 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, app_func,
690 pkgmgrinfo_appinfo_filter_destroy(filter);
695 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
696 pkgmgrinfo_app_list_cb app_func, void *user_data)
698 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
701 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
703 if (app_func == NULL) {
704 LOGE("invalid parameter");
705 return PMINFO_R_EINVAL;
708 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
712 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
714 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
717 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
719 if (app_func == NULL) {
720 LOGE("invalid parameter");
721 return PMINFO_R_EINVAL;
724 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
728 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
730 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
733 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
735 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
737 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
738 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
740 if (info->app_info == NULL || info->app_info->appid == NULL)
741 return PMINFO_R_ERROR;
742 *appid = (char *)info->app_info->appid;
747 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
749 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
751 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
752 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
754 if (info->package == NULL)
755 return PMINFO_R_ERROR;
757 *pkg_name = (char *)info->package;
762 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
764 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
766 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
767 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
769 if (info->package == NULL)
770 return PMINFO_R_ERROR;
772 *pkgid = (char *)info->package;
777 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
779 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
781 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
782 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
784 if (info->app_info == NULL || info->app_info->exec == NULL)
785 return PMINFO_R_ERROR;
786 *exec = (char *)info->app_info->exec;
792 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
797 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
799 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
800 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
802 locale = info->locale;
803 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
805 start = info->app_info->icon;
806 for (ptr = start; ptr != NULL; ptr = ptr->next) {
807 if (ptr->lang == NULL)
810 if (strcmp(ptr->lang, locale) == 0) {
811 *icon = (char *)ptr->text;
812 if (strcasecmp(*icon, "(null)") == 0) {
813 locale = DEFAULT_LOCALE;
818 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
819 *icon = (char *)ptr->text;
824 return PMINFO_R_ERROR;
828 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
833 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
835 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
836 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
838 locale = info->locale;
839 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
841 start = info->app_info->label;
842 for (ptr = start; ptr != NULL; ptr = ptr->next) {
843 if (ptr->lang == NULL)
846 if (strcmp(ptr->lang, locale) == 0) {
847 *label = (char *)ptr->text;
848 if (strcasecmp(*label, "(null)") == 0) {
849 locale = DEFAULT_LOCALE;
854 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
855 *label = (char *)ptr->text;
860 return PMINFO_R_ERROR;
863 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
867 sqlite3_stmt *stmt = NULL;
870 const char *manifest_db;
872 manifest_db = getUserPkgParserDBPathUID(uid);
873 if (manifest_db == NULL) {
874 _LOGE("Failed to get manifest db path");
878 if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
879 _LOGE("DB open fail\n");
883 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
885 _LOGE("Out of memory");
889 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
890 _LOGE("prepare_v2 fail\n");
894 if (sqlite3_step(stmt) == SQLITE_ROW) {
895 val = (char *)sqlite3_column_text(stmt, 0);
897 result = strdup(val);
901 sqlite3_finalize(stmt);
908 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
912 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
914 val = _get_localed_label(appid, locale, uid);
916 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
919 return PMINFO_R_ERROR;
926 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
928 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
931 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
933 if ( strcasecmp(comp, "uiapp") == 0)
934 return PMINFO_UI_APP;
935 else if ( strcasecmp(comp, "svcapp") == 0)
936 return PMINFO_SVC_APP;
941 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
943 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
946 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
947 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
949 if (info->app_info == NULL)
950 return PMINFO_R_ERROR;
952 comp = __appcomponent_convert(info->app_info->component);
954 return PMINFO_R_ERROR;
961 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
963 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
965 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
966 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
968 if (info->app_info == NULL || info->app_info->type == NULL)
969 return PMINFO_R_ERROR;
970 *app_type = (char *)info->app_info->type;
975 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
976 int *operation_count, char ***operation)
978 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
979 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
980 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
981 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
982 *operation_count = data->operation_count;
983 *operation = data->operation;
987 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
988 int *uri_count, char ***uri)
990 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
991 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
992 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
993 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
994 *uri_count = data->uri_count;
999 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
1000 int *mime_count, char ***mime)
1002 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1003 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1004 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1005 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1006 *mime_count = data->mime_count;
1011 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1012 int *subapp_count, char ***subapp)
1014 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1015 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1016 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1017 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1018 *subapp_count = data->subapp_count;
1019 *subapp = data->subapp;
1023 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1027 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1029 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1030 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1032 for (ptr = info->app_info->icon; ptr != NULL; ptr = ptr->next) {
1033 if (ptr->section == NULL)
1036 val = (char *)ptr->section;
1037 if (val && strcmp(val, "setting") == 0) {
1038 *icon = (char *)ptr->text;
1043 return PMINFO_R_ERROR;
1047 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1051 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1053 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1054 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1056 for (ptr = info->app_info->icon; ptr != NULL; ptr = ptr->next) {
1057 if (ptr->section == NULL)
1060 val = (char *)ptr->section;
1061 if (val && strcmp(val, "notification") == 0){
1062 *icon = (char *)ptr->text;
1067 return PMINFO_R_ERROR;
1070 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1073 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1075 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1076 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1078 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1079 return PMINFO_R_ERROR;
1081 val = (char *)info->app_info->recentimage;
1082 if (strcasecmp(val, "capture") == 0)
1083 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1084 else if (strcasecmp(val, "icon") == 0)
1085 *type = PMINFO_RECENTIMAGE_USE_ICON;
1087 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1092 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1096 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1098 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1099 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1101 for (ptr = info->app_info->image; ptr != NULL; ptr = ptr->next) {
1102 if (ptr->section == NULL)
1105 val = (char *)ptr->section;
1106 if (val && strcmp(val, "preview") == 0) {
1107 *preview_img = (char *)ptr->text;
1112 return PMINFO_R_ERROR;
1115 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1118 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1120 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1121 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1123 val = info->app_info->permission_type;
1125 return PMINFO_R_ERROR;
1127 if (strcmp(val, "signature") == 0)
1128 *permission = PMINFO_PERMISSION_SIGNATURE;
1129 else if (strcmp(val, "privilege") == 0)
1130 *permission = PMINFO_PERMISSION_PRIVILEGE;
1132 *permission = PMINFO_PERMISSION_NORMAL;
1137 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1139 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1141 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1142 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1144 if (info->app_info == NULL || info->app_info->component_type == NULL)
1145 return PMINFO_R_ERROR;
1147 *component_type = (char *)info->app_info->component_type;
1152 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1155 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1157 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1158 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1160 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1161 return PMINFO_R_ERROR;
1163 val = (char *)info->app_info->hwacceleration;
1164 if (strcasecmp(val, "not-use-GL") == 0)
1165 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
1166 else if (strcasecmp(val, "use-GL") == 0)
1167 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
1169 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
1174 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1177 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1179 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1180 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1182 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1183 return PMINFO_R_ERROR;
1185 val = (char *)info->app_info->screenreader;
1186 if (strcasecmp(val, "screenreader-off") == 0)
1187 *screenreader = PMINFO_SCREENREADER_OFF;
1188 else if (strcasecmp(val, "screenreader-on") == 0)
1189 *screenreader = PMINFO_SCREENREADER_ON;
1191 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1196 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1198 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1200 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1201 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1202 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1204 if (info->app_info == NULL || info->app_info->portraitimg ||
1205 info->app_info->landscapeimg == NULL)
1206 return PMINFO_R_ERROR;
1208 *portrait_img = (char *)info->app_info->portraitimg;
1209 *landscape_img = (char *)info->app_info->landscapeimg;
1214 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
1216 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1218 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1219 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1221 if (info->app_info == NULL || info->app_info->submode_mainid == NULL)
1222 return PMINFO_R_ERROR;
1224 *submode_mainid = (char *)info->app_info->submode_mainid;
1229 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
1231 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1233 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1234 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1236 if (info->app_info->launch_mode == NULL)
1237 return PMINFO_R_ERROR;
1239 *mode = (char *)(info->app_info->launch_mode);
1244 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
1246 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1247 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1248 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1249 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1251 int ret = PMINFO_R_OK;
1253 sqlite3_stmt *stmt = NULL;
1256 ret = __open_manifest_db(uid);
1257 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1259 /*Start constructing query*/
1260 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
1263 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1264 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1267 ret = sqlite3_step(stmt);
1268 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1270 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1271 *access = strdup((char *)sqlite3_column_text(stmt, 2));
1276 sqlite3_free(query);
1277 sqlite3_finalize(stmt);
1278 __close_manifest_db();
1282 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
1284 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
1287 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
1289 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1290 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1292 int ret = PMINFO_R_OK;
1294 sqlite3_stmt *stmt = NULL;
1297 ret = __open_manifest_db(uid);
1298 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1300 /*Start constructing query*/
1301 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
1304 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1305 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1308 ret = sqlite3_step(stmt);
1309 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1311 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1316 sqlite3_free(query);
1317 sqlite3_finalize(stmt);
1318 __close_manifest_db();
1322 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1324 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
1327 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
1328 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
1330 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1331 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1333 permission_x *ptr = NULL;
1334 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1336 if (info->app_info == NULL)
1337 return PMINFO_R_ERROR;
1339 for (ptr = info->app_info->permission; ptr; ptr = ptr->next) {
1341 ret = permission_func(ptr->value, user_data);
1349 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
1350 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
1352 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1353 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1355 category_x *ptr = NULL;
1356 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1358 if (info->app_info == NULL)
1359 return PMINFO_R_ERROR;
1361 for (ptr = info->app_info->category; ptr; ptr = ptr->next) {
1363 ret = category_func(ptr->name, user_data);
1371 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
1372 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
1374 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1375 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1377 metadata_x *ptr = NULL;
1378 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1380 if (info->app_info == NULL)
1381 return PMINFO_R_ERROR;
1383 for (ptr = info->app_info->metadata; ptr; ptr = ptr->next) {
1385 ret = metadata_func(ptr->key, ptr->value, user_data);
1393 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
1394 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1396 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1397 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1399 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1400 appcontrol_x *appcontrol;
1402 if (info->uiapp_info == NULL)
1403 return PMINFO_R_ERROR;
1405 for (appcontrol = info->app_info->appcontrol; appcontrol; appcontrol = appcontrol->next) {
1406 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1414 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
1416 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1417 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1418 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1420 if (info->app_info == NULL)
1421 return PMINFO_R_ERROR;
1423 *nodisplay = _get_bool_value(info->app_info->nodisplay);
1427 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
1429 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1430 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1431 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1433 if (info->app_info == NULL)
1434 return PMINFO_R_ERROR;
1436 *multiple = _get_bool_value(info->app_info->multiple);
1440 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
1442 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1443 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1444 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1446 if (info->app_info == NULL)
1447 return PMINFO_R_ERROR;
1449 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
1453 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
1455 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1456 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1457 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1459 if (info->app_info == NULL)
1460 return PMINFO_R_ERROR;
1462 *taskmanage = _get_bool_value(info->app_info->taskmanage);
1466 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
1468 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1469 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1470 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1472 if (info->app_info == NULL)
1473 return PMINFO_R_ERROR;
1475 *enabled = _get_bool_value(info->app_info->enabled);
1480 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
1482 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1483 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1484 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1486 if (info->app_info == NULL)
1487 return PMINFO_R_ERROR;
1489 *onboot = _get_bool_value(info->app_info->onboot);
1493 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
1495 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1496 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1497 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1499 if (info->app_info == NULL)
1500 return PMINFO_R_ERROR;
1502 *autorestart = _get_bool_value(info->app_info->autorestart);
1506 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
1508 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1509 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1510 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1512 if (info->app_info == NULL)
1513 return PMINFO_R_ERROR;
1515 *mainapp = _get_bool_value(info->app_info->mainapp);
1519 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
1521 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1522 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1523 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1525 if (info->app_info == NULL)
1526 return PMINFO_R_ERROR;
1528 *preload = _get_bool_value(info->app_info->preload);
1532 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
1534 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1535 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1536 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1538 if (info->app_info == NULL)
1539 return PMINFO_R_ERROR;
1541 *submode = _get_bool_value(info->app_info->submode);
1545 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
1547 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1548 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
1549 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
1551 category_x *ptr = NULL;
1552 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1554 if (info->app_info == NULL)
1555 return PMINFO_R_ERROR;
1558 for (ptr = info->app_info->category; ptr; ptr = ptr->next) {
1560 if (strcasecmp(ptr->name, category) == 0) {
1570 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
1573 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1575 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
1576 _LOGE("invalid parameter");
1577 return PMINFO_R_EINVAL;
1580 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
1585 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
1587 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1588 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1589 __cleanup_appinfo(info);
1593 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
1595 return (pkgmgrinfo_pkginfo_filter_create(handle));
1598 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
1600 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1603 static gint __compare_func(gconstpointer data1, gconstpointer data2)
1605 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
1606 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
1607 if (node1->prop == node2->prop)
1609 else if (node1->prop > node2->prop)
1615 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
1616 const char *property, const int value)
1618 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1619 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1620 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1622 GSList *link = NULL;
1624 prop = _pminfo_appinfo_convert_to_prop_int(property);
1625 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
1626 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
1627 _LOGE("Invalid Integer Property\n");
1628 return PMINFO_R_EINVAL;
1630 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1631 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1633 _LOGE("Out of Memory!!!\n");
1634 return PMINFO_R_ERROR;
1636 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1637 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1639 _LOGE("Out of Memory\n");
1642 return PMINFO_R_ERROR;
1646 /*If API is called multiple times for same property, we should override the previous values.
1647 Last value set will be used for filtering.*/
1648 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1650 filter->list = g_slist_delete_link(filter->list, link);
1651 filter->list = g_slist_append(filter->list, (gpointer)node);
1656 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
1657 const char *property, const bool value)
1659 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1660 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1662 GSList *link = NULL;
1664 prop = _pminfo_appinfo_convert_to_prop_bool(property);
1665 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
1666 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
1667 _LOGE("Invalid Boolean Property\n");
1668 return PMINFO_R_EINVAL;
1670 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1671 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1673 _LOGE("Out of Memory!!!\n");
1674 return PMINFO_R_ERROR;
1677 val = strndup("('true','True')", 15);
1679 val = strndup("('false','False')", 17);
1681 _LOGE("Out of Memory\n");
1684 return PMINFO_R_ERROR;
1688 /*If API is called multiple times for same property, we should override the previous values.
1689 Last value set will be used for filtering.*/
1690 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1692 filter->list = g_slist_delete_link(filter->list, link);
1693 filter->list = g_slist_append(filter->list, (gpointer)node);
1698 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
1699 const char *property, const char *value)
1701 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1702 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1703 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1705 pkgmgrinfo_node_x *ptr = NULL;
1706 char prev[PKG_STRING_LEN_MAX] = {'\0'};
1707 char temp[PKG_STRING_LEN_MAX] = {'\0'};
1708 GSList *link = NULL;
1710 prop = _pminfo_appinfo_convert_to_prop_str(property);
1711 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
1712 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
1713 _LOGE("Invalid String Property\n");
1714 return PMINFO_R_EINVAL;
1716 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1717 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1719 _LOGE("Out of Memory!!!\n");
1720 return PMINFO_R_ERROR;
1724 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
1725 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
1726 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
1728 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
1730 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1732 filter->list = g_slist_delete_link(filter->list, link);
1733 filter->list = g_slist_append(filter->list, (gpointer)node);
1735 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
1736 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
1737 case E_PMINFO_APPINFO_PROP_APP_URI:
1738 case E_PMINFO_APPINFO_PROP_APP_MIME:
1739 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
1741 _LOGE("Out of Memory\n");
1744 return PMINFO_R_ERROR;
1746 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1748 ptr = (pkgmgrinfo_node_x *)link->data;
1749 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
1750 _LOGE("Previous value is %s\n", prev);
1751 filter->list = g_slist_delete_link(filter->list, link);
1752 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
1753 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1754 _LOGE("New value is %s\n", val);
1756 filter->list = g_slist_append(filter->list, (gpointer)node);
1757 memset(temp, '\0', PKG_STRING_LEN_MAX);
1759 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
1760 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1761 _LOGE("First value is %s\n", val);
1763 filter->list = g_slist_append(filter->list, (gpointer)node);
1764 memset(temp, '\0', PKG_STRING_LEN_MAX);
1768 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
1769 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1771 filter->list = g_slist_delete_link(filter->list, link);
1772 filter->list = g_slist_append(filter->list, (gpointer)node);
1778 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
1780 int *p = (int*)data;
1781 *p = atoi(coltxt[0]);
1782 _LOGE("count value is %d\n", *p);
1786 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
1788 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1789 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1790 char *locale = NULL;
1791 char *condition = NULL;
1792 char *error_message = NULL;
1793 char query[MAX_QUERY_LEN] = {'\0'};
1794 char where[MAX_QUERY_LEN] = {'\0'};
1798 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1799 /*Get current locale*/
1800 locale = _get_system_locale();
1801 if (locale == NULL) {
1802 _LOGE("manifest locale is NULL\n");
1803 return PMINFO_R_ERROR;
1806 ret = __open_manifest_db(uid);
1808 _LOGE("Fail to open manifest DB\n");
1810 return PMINFO_R_ERROR;
1813 /*Start constructing query*/
1814 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
1816 /*Get where clause*/
1817 for (list = filter->list; list; list = g_slist_next(list)) {
1818 __get_filter_condition(list->data, &condition);
1820 strncat(where, condition, sizeof(where) - strlen(where) -1);
1821 where[sizeof(where) - 1] = '\0';
1825 if (g_slist_next(list)) {
1826 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
1827 where[sizeof(where) - 1] = '\0';
1830 if (strlen(where) > 0) {
1831 strncat(query, where, sizeof(query) - strlen(query) - 1);
1832 query[sizeof(query) - 1] = '\0';
1837 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
1838 _LOGE("Don't execute query = %s error message = %s\n", query,
1840 sqlite3_free(error_message);
1841 ret = PMINFO_R_ERROR;
1851 __close_manifest_db();
1855 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
1857 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
1860 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
1861 pkgmgrinfo_appinfo_filter_h handle,
1862 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
1864 if (handle == NULL || app_cb == NULL) {
1865 LOGE("invalid parameter");
1866 return PMINFO_R_EINVAL;
1869 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
1873 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
1874 pkgmgrinfo_app_list_cb app_cb, void * user_data)
1876 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
1879 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
1881 return (pkgmgrinfo_pkginfo_filter_create(handle));
1884 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
1886 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1889 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
1890 const char *key, const char *value)
1892 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
1893 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
1894 /*value can be NULL. In that case all apps with specified key should be displayed*/
1898 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1899 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1900 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
1902 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
1906 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
1909 /*If API is called multiple times, we should OR all conditions.*/
1910 filter->list = g_slist_append(filter->list, (gpointer)node);
1911 /*All memory will be freed in destroy API*/
1929 static void __get_metadata_filter_condition(gpointer data, char **condition)
1931 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
1932 char key[MAX_QUERY_LEN] = {'\0'};
1933 char value[MAX_QUERY_LEN] = {'\0'};
1935 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
1938 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
1943 *condition = strdup(key);
1947 static char *_get_metadata_filtered_query(const char *query_raw,
1948 pkgmgrinfo_filter_x *filter)
1950 char buf[MAX_QUERY_LEN] = { 0, };
1954 GSList *head = NULL;
1957 head = filter->list;
1959 strncat(buf, query_raw, MAX_QUERY_LEN - 1);
1961 for (list = head; list; list = list->next) {
1962 /* TODO: revise condition getter function */
1963 __get_metadata_filter_condition(list->data, &condition);
1964 if (condition == NULL)
1966 if (buf[strlen(query_raw)] == '\0') {
1967 len += strlen(" WHERE ");
1968 strncat(buf, " WHERE ", MAX_QUERY_LEN - len - 1);
1970 len += strlen(" AND ");
1971 strncat(buf, " AND ", MAX_QUERY_LEN -len - 1);
1973 len += strlen(condition);
1974 strncat(buf, condition, sizeof(buf) - len - 1);
1982 static GSList *_appinfo_get_metadata_filtered_list(pkgmgrinfo_filter_x *filter)
1984 static const char query_raw[] =
1985 "SELECT app_id FROM package_app_app_metadata";
1989 GSList *list = NULL;
1992 query = _get_metadata_filtered_query(query_raw, filter);
1993 if (query == NULL) {
1994 LOGE("out of memory");
1998 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
2001 if (ret != SQLITE_OK) {
2002 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
2006 while (sqlite3_step(stmt) == SQLITE_ROW) {
2007 _save_column_str(stmt, 0, (const char **)&appid);
2008 list = g_slist_append(list, appid);
2011 sqlite3_finalize(stmt);
2016 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2017 pkgmgrinfo_appinfo_metadata_filter_h handle,
2018 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2023 pkgmgrinfo_appinfo_h info;
2026 if (handle == NULL || app_cb == NULL) {
2027 LOGE("invalid parameter");
2028 return PMINFO_R_EINVAL;
2031 if (__open_manifest_db(uid) < 0)
2032 return PMINFO_R_ERROR;
2034 list = _appinfo_get_metadata_filtered_list(handle);
2037 __close_manifest_db();
2041 for (tmp = list; tmp; tmp = tmp->next) {
2042 appid = (char *)tmp->data;
2044 if (pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid,
2049 if (app_cb(info, user_data) < 0)
2051 pkgmgrinfo_appinfo_destroy_appinfo(info);
2057 __close_manifest_db();
2062 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
2063 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2065 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, user_data, GLOBAL_USER);
2068 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2071 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2073 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2074 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2076 val = info->uiapp_info->guestmode_visibility;
2077 *status = _get_bool_value(val);