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_metadata(const char *appid, metadata_x **metadata)
424 static const char query_raw[] =
425 "SELECT md_key, md_value "
426 "FROM package_app_app_metadata WHERE app_id=%Q";
433 query = sqlite3_mprintf(query_raw, appid);
435 LOGE("out of memory");
436 return PMINFO_R_ERROR;
439 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
442 if (ret != SQLITE_OK) {
443 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
444 return PMINFO_R_ERROR;
447 while (sqlite3_step(stmt) == SQLITE_ROW) {
448 info = calloc(1, sizeof(metadata_x));
450 LOGE("out of memory");
451 sqlite3_finalize(stmt);
453 LISTHEAD(*metadata, info);
456 return PMINFO_R_ERROR;
459 _save_column_str(stmt, idx++, &info->key);
460 _save_column_str(stmt, idx++, &info->value);
461 LISTADD(*metadata, info);
465 LISTHEAD(*metadata, info);
469 sqlite3_finalize(stmt);
475 static int _appinfo_get_app(const char *appid, const char *locale,
476 pkgmgr_appinfo_x **appinfo)
478 static const char query_raw[] =
479 "SELECT app_id, app_component, app_exec, app_nodisplay, "
480 "app_type, app_onboot, app_multiple, app_autorestart, "
481 "app_taskmanage, app_enabled, app_hwacceleration, "
482 "app_screenreader, app_mainapp, app_recentimage, "
483 "app_launchcondition, app_indicatordisplay, app_portraitimg, "
484 "app_landscapeimg, app_guestmodevisibility, "
485 "app_permissiontype, app_preload, app_submode, "
486 "app_submode_mainid, app_launch_mode, app_ui_gadget, "
487 "component_type, package "
488 "FROM package_app_info WHERE app_id=%Q";
493 pkgmgr_appinfo_x *info;
496 query = sqlite3_mprintf(query_raw, appid);
498 LOGE("out of memory");
499 return PMINFO_R_ERROR;
502 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
505 if (ret != SQLITE_OK) {
506 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
507 return PMINFO_R_ERROR;
510 ret = sqlite3_step(stmt);
511 if (ret == SQLITE_DONE) {
512 LOGE("cannot find app");
513 sqlite3_finalize(stmt);
514 return PMINFO_R_ENOENT;
515 } else if (ret != SQLITE_ROW) {
516 LOGE("step failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
517 sqlite3_finalize(stmt);
518 return PMINFO_R_ERROR;
521 app = calloc(1, sizeof(application_x));
523 LOGE("out of memory");
524 sqlite3_finalize(stmt);
525 return PMINFO_R_ERROR;
528 _save_column_str(stmt, idx++, &app->appid);
529 _save_column_str(stmt, idx++, &app->component);
530 _save_column_str(stmt, idx++, &app->exec);
531 _save_column_str(stmt, idx++, &app->nodisplay);
532 _save_column_str(stmt, idx++, &app->type);
533 _save_column_str(stmt, idx++, &app->onboot);
534 _save_column_str(stmt, idx++, &app->multiple);
535 _save_column_str(stmt, idx++, &app->autorestart);
536 _save_column_str(stmt, idx++, &app->taskmanage);
537 _save_column_str(stmt, idx++, &app->enabled);
538 _save_column_str(stmt, idx++, &app->hwacceleration);
539 _save_column_str(stmt, idx++, &app->screenreader);
540 _save_column_str(stmt, idx++, &app->mainapp);
541 _save_column_str(stmt, idx++, &app->recentimage);
542 _save_column_str(stmt, idx++, &app->launchcondition);
543 _save_column_str(stmt, idx++, &app->indicatordisplay);
544 _save_column_str(stmt, idx++, &app->portraitimg);
545 _save_column_str(stmt, idx++, &app->landscapeimg);
546 _save_column_str(stmt, idx++, &app->guestmode_visibility);
547 _save_column_str(stmt, idx++, &app->permission_type);
548 _save_column_str(stmt, idx++, &app->preload);
549 _save_column_str(stmt, idx++, &app->submode);
550 _save_column_str(stmt, idx++, &app->submode_mainid);
551 _save_column_str(stmt, idx++, &app->launch_mode);
552 _save_column_str(stmt, idx++, &app->ui_gadget);
553 _save_column_str(stmt, idx++, &app->component_type);
554 _save_column_str(stmt, idx++, &app->package);
556 if (_appinfo_get_label(app->appid, locale, &app->label)) {
557 pkgmgrinfo_basic_free_application(app);
558 sqlite3_finalize(stmt);
559 return PMINFO_R_ERROR;
562 if (_appinfo_get_icon(app->appid, locale, &app->icon)) {
563 pkgmgrinfo_basic_free_application(app);
564 sqlite3_finalize(stmt);
565 return PMINFO_R_ERROR;
568 if (_appinfo_get_category(app->appid, &app->category)) {
569 pkgmgrinfo_basic_free_application(app);
570 sqlite3_finalize(stmt);
571 return PMINFO_R_ERROR;
574 if (_appinfo_get_app_control(app->appid, &app->appcontrol)) {
575 pkgmgrinfo_basic_free_application(app);
576 sqlite3_finalize(stmt);
577 return PMINFO_R_ERROR;
580 if (_appinfo_get_data_control(app->appid, &app->datacontrol)) {
581 pkgmgrinfo_basic_free_application(app);
582 sqlite3_finalize(stmt);
583 return PMINFO_R_ERROR;
586 if (_appinfo_get_metadata(app->appid, &app->metadata)) {
587 pkgmgrinfo_basic_free_application(app);
588 sqlite3_finalize(stmt);
589 return PMINFO_R_ERROR;
592 info = calloc(1, sizeof(pkgmgr_appinfo_x));
594 LOGE("out of memory");
595 pkgmgrinfo_basic_free_application(app);
596 sqlite3_finalize(stmt);
597 return PMINFO_R_ERROR;
600 info->package = strdup(app->package);
601 info->app_info = app;
602 info->locale = strdup(locale);
605 sqlite3_finalize(stmt);
610 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
611 pkgmgrinfo_appinfo_h *handle)
613 pkgmgr_appinfo_x *appinfo = NULL;
616 if (appid == NULL || handle == NULL) {
617 LOGE("invalid parameter");
618 return PMINFO_R_EINVAL;
621 if (__open_manifest_db(uid) < 0)
622 return PMINFO_R_ERROR;
624 locale = _get_system_locale();
625 if (locale == NULL) {
626 __close_manifest_db();
627 return PMINFO_R_ERROR;
630 if (_appinfo_get_app(appid, locale, &appinfo)) {
632 __close_manifest_db();
633 return PMINFO_R_ERROR;
639 __close_manifest_db();
644 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
646 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
649 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
650 pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb,
653 pkgmgr_appinfo_x *info;
660 if (__open_manifest_db(uid) < 0)
661 return PMINFO_R_ERROR;
663 locale = _get_system_locale();
664 if (locale == NULL) {
665 __close_manifest_db();
666 return PMINFO_R_ERROR;
669 list = _appinfo_get_filtered_list(locale, filter);
672 __close_manifest_db();
676 for (tmp = list; tmp; tmp = tmp->next) {
677 appid = (char *)tmp->data;
679 if (_appinfo_get_app(appid, locale, &info)) {
683 if (app_list_cb(info, user_data) < 0)
685 pkgmgrinfo_appinfo_destroy_appinfo(info);
692 __close_manifest_db();
697 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
698 pkgmgrinfo_app_component component,
699 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
702 pkgmgrinfo_appinfo_filter_h filter;
704 const char *comp_str = NULL;
706 if (handle == NULL || app_func == NULL) {
707 LOGE("invalied parameter");
708 return PMINFO_R_EINVAL;
711 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
712 LOGE("invalid parameter");
713 return PMINFO_R_EINVAL;
716 if (pkgmgrinfo_appinfo_filter_create(&filter))
717 return PMINFO_R_ERROR;
719 if (pkgmgrinfo_appinfo_filter_add_string(filter,
720 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
721 pkgmgrinfo_appinfo_filter_destroy(filter);
722 return PMINFO_R_ERROR;
728 comp_str = PMINFO_APPINFO_UI_APP;
731 comp_str = PMINFO_APPINFO_SVC_APP;
738 if (pkgmgrinfo_appinfo_filter_add_string(filter,
739 PMINFO_APPINFO_PROP_APP_COMPONENT,
741 pkgmgrinfo_appinfo_filter_destroy(filter);
742 return PMINFO_R_ERROR;
746 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, app_func,
749 pkgmgrinfo_appinfo_filter_destroy(filter);
754 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
755 pkgmgrinfo_app_list_cb app_func, void *user_data)
757 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
760 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
762 if (app_func == NULL) {
763 LOGE("invalid parameter");
764 return PMINFO_R_EINVAL;
767 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
771 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
773 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
776 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
778 if (app_func == NULL) {
779 LOGE("invalid parameter");
780 return PMINFO_R_EINVAL;
783 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
787 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
789 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
792 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
794 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
796 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
797 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
799 if (info->app_info == NULL || info->app_info->appid == NULL)
800 return PMINFO_R_ERROR;
801 *appid = (char *)info->app_info->appid;
806 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
808 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
810 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
811 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
813 if (info->package == NULL)
814 return PMINFO_R_ERROR;
816 *pkg_name = (char *)info->package;
821 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
823 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
825 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
826 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
828 if (info->package == NULL)
829 return PMINFO_R_ERROR;
831 *pkgid = (char *)info->package;
836 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
838 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
840 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
841 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
843 if (info->app_info == NULL || info->app_info->exec == NULL)
844 return PMINFO_R_ERROR;
845 *exec = (char *)info->app_info->exec;
851 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
856 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
858 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
859 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
861 locale = info->locale;
862 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
864 start = info->app_info->icon;
865 for (ptr = start; ptr != NULL; ptr = ptr->next) {
866 if (ptr->lang == NULL)
869 if (strcmp(ptr->lang, locale) == 0) {
870 *icon = (char *)ptr->text;
871 if (strcasecmp(*icon, "(null)") == 0) {
872 locale = DEFAULT_LOCALE;
877 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
878 *icon = (char *)ptr->text;
883 return PMINFO_R_ERROR;
887 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
892 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
894 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
895 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
897 locale = info->locale;
898 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
900 start = info->app_info->label;
901 for (ptr = start; ptr != NULL; ptr = ptr->next) {
902 if (ptr->lang == NULL)
905 if (strcmp(ptr->lang, locale) == 0) {
906 *label = (char *)ptr->text;
907 if (strcasecmp(*label, "(null)") == 0) {
908 locale = DEFAULT_LOCALE;
913 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
914 *label = (char *)ptr->text;
919 return PMINFO_R_ERROR;
922 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
926 sqlite3_stmt *stmt = NULL;
929 const char *manifest_db;
931 manifest_db = getUserPkgParserDBPathUID(uid);
932 if (manifest_db == NULL) {
933 _LOGE("Failed to get manifest db path");
937 if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
938 _LOGE("DB open fail\n");
942 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
944 _LOGE("Out of memory");
948 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
949 _LOGE("prepare_v2 fail\n");
953 if (sqlite3_step(stmt) == SQLITE_ROW) {
954 val = (char *)sqlite3_column_text(stmt, 0);
956 result = strdup(val);
960 sqlite3_finalize(stmt);
967 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
971 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
973 val = _get_localed_label(appid, locale, uid);
975 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
978 return PMINFO_R_ERROR;
985 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
987 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
990 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
992 if ( strcasecmp(comp, "uiapp") == 0)
993 return PMINFO_UI_APP;
994 else if ( strcasecmp(comp, "svcapp") == 0)
995 return PMINFO_SVC_APP;
1000 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1002 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1005 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1006 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1008 if (info->app_info == NULL)
1009 return PMINFO_R_ERROR;
1011 comp = __appcomponent_convert(info->app_info->component);
1013 return PMINFO_R_ERROR;
1020 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1022 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1024 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1025 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1027 if (info->app_info == NULL || info->app_info->type == NULL)
1028 return PMINFO_R_ERROR;
1029 *app_type = (char *)info->app_info->type;
1034 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
1035 int *operation_count, char ***operation)
1037 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1038 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1039 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1040 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1041 *operation_count = data->operation_count;
1042 *operation = data->operation;
1046 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
1047 int *uri_count, char ***uri)
1049 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1050 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1051 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1052 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1053 *uri_count = data->uri_count;
1058 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
1059 int *mime_count, char ***mime)
1061 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1062 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1063 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1064 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1065 *mime_count = data->mime_count;
1070 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1071 int *subapp_count, char ***subapp)
1073 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1074 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1075 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1076 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1077 *subapp_count = data->subapp_count;
1078 *subapp = data->subapp;
1082 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1086 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1088 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1089 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1091 for (ptr = info->app_info->icon; ptr != NULL; ptr = ptr->next) {
1092 if (ptr->section == NULL)
1095 val = (char *)ptr->section;
1096 if (val && strcmp(val, "setting") == 0) {
1097 *icon = (char *)ptr->text;
1102 return PMINFO_R_ERROR;
1106 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1110 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1112 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1113 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1115 for (ptr = info->app_info->icon; ptr != NULL; ptr = ptr->next) {
1116 if (ptr->section == NULL)
1119 val = (char *)ptr->section;
1120 if (val && strcmp(val, "notification") == 0){
1121 *icon = (char *)ptr->text;
1126 return PMINFO_R_ERROR;
1129 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1132 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1134 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1135 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1137 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1138 return PMINFO_R_ERROR;
1140 val = (char *)info->app_info->recentimage;
1141 if (strcasecmp(val, "capture") == 0)
1142 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1143 else if (strcasecmp(val, "icon") == 0)
1144 *type = PMINFO_RECENTIMAGE_USE_ICON;
1146 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1151 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1155 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1157 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1158 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1160 for (ptr = info->app_info->image; ptr != NULL; ptr = ptr->next) {
1161 if (ptr->section == NULL)
1164 val = (char *)ptr->section;
1165 if (val && strcmp(val, "preview") == 0) {
1166 *preview_img = (char *)ptr->text;
1171 return PMINFO_R_ERROR;
1174 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1177 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1179 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1180 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1182 val = info->app_info->permission_type;
1184 return PMINFO_R_ERROR;
1186 if (strcmp(val, "signature") == 0)
1187 *permission = PMINFO_PERMISSION_SIGNATURE;
1188 else if (strcmp(val, "privilege") == 0)
1189 *permission = PMINFO_PERMISSION_PRIVILEGE;
1191 *permission = PMINFO_PERMISSION_NORMAL;
1196 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1198 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1200 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1201 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1203 if (info->app_info == NULL || info->app_info->component_type == NULL)
1204 return PMINFO_R_ERROR;
1206 *component_type = (char *)info->app_info->component_type;
1211 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1214 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1216 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1217 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1219 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1220 return PMINFO_R_ERROR;
1222 val = (char *)info->app_info->hwacceleration;
1223 if (strcasecmp(val, "not-use-GL") == 0)
1224 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
1225 else if (strcasecmp(val, "use-GL") == 0)
1226 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
1228 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
1233 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1236 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1238 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1239 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1241 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1242 return PMINFO_R_ERROR;
1244 val = (char *)info->app_info->screenreader;
1245 if (strcasecmp(val, "screenreader-off") == 0)
1246 *screenreader = PMINFO_SCREENREADER_OFF;
1247 else if (strcasecmp(val, "screenreader-on") == 0)
1248 *screenreader = PMINFO_SCREENREADER_ON;
1250 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1255 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1257 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1259 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1260 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1261 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1263 if (info->app_info == NULL || info->app_info->portraitimg ||
1264 info->app_info->landscapeimg == NULL)
1265 return PMINFO_R_ERROR;
1267 *portrait_img = (char *)info->app_info->portraitimg;
1268 *landscape_img = (char *)info->app_info->landscapeimg;
1273 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
1275 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1277 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1278 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1280 if (info->app_info == NULL || info->app_info->submode_mainid == NULL)
1281 return PMINFO_R_ERROR;
1283 *submode_mainid = (char *)info->app_info->submode_mainid;
1288 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
1290 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1292 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1293 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1295 if (info->app_info->launch_mode == NULL)
1296 return PMINFO_R_ERROR;
1298 *mode = (char *)(info->app_info->launch_mode);
1303 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
1305 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1306 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1307 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1308 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1310 int ret = PMINFO_R_OK;
1312 sqlite3_stmt *stmt = NULL;
1315 ret = __open_manifest_db(uid);
1316 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1318 /*Start constructing query*/
1319 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
1322 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1323 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1326 ret = sqlite3_step(stmt);
1327 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1329 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1330 *access = strdup((char *)sqlite3_column_text(stmt, 2));
1335 sqlite3_free(query);
1336 sqlite3_finalize(stmt);
1337 __close_manifest_db();
1341 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
1343 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
1346 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
1348 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1349 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1351 int ret = PMINFO_R_OK;
1353 sqlite3_stmt *stmt = NULL;
1356 ret = __open_manifest_db(uid);
1357 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1359 /*Start constructing query*/
1360 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
1363 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1364 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1367 ret = sqlite3_step(stmt);
1368 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1370 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1375 sqlite3_free(query);
1376 sqlite3_finalize(stmt);
1377 __close_manifest_db();
1381 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1383 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
1386 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
1387 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
1389 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1390 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1392 permission_x *ptr = NULL;
1393 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1395 if (info->app_info == NULL)
1396 return PMINFO_R_ERROR;
1398 for (ptr = info->app_info->permission; ptr; ptr = ptr->next) {
1400 ret = permission_func(ptr->value, user_data);
1408 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
1409 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
1411 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1412 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1414 category_x *ptr = NULL;
1415 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1417 if (info->app_info == NULL)
1418 return PMINFO_R_ERROR;
1420 for (ptr = info->app_info->category; ptr; ptr = ptr->next) {
1422 ret = category_func(ptr->name, user_data);
1430 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
1431 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
1433 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1434 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1436 metadata_x *ptr = NULL;
1437 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1439 if (info->app_info == NULL)
1440 return PMINFO_R_ERROR;
1442 for (ptr = info->app_info->metadata; ptr; ptr = ptr->next) {
1444 ret = metadata_func(ptr->key, ptr->value, user_data);
1452 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
1453 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1455 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1456 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1458 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1459 appcontrol_x *appcontrol;
1461 if (info->uiapp_info == NULL)
1462 return PMINFO_R_ERROR;
1464 for (appcontrol = info->app_info->appcontrol; appcontrol; appcontrol = appcontrol->next) {
1465 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1473 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
1475 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1476 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1477 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1479 if (info->app_info == NULL)
1480 return PMINFO_R_ERROR;
1482 *nodisplay = _get_bool_value(info->app_info->nodisplay);
1486 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
1488 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1489 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1490 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1492 if (info->app_info == NULL)
1493 return PMINFO_R_ERROR;
1495 *multiple = _get_bool_value(info->app_info->multiple);
1499 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
1501 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1502 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1503 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1505 if (info->app_info == NULL)
1506 return PMINFO_R_ERROR;
1508 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
1512 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
1514 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1515 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1516 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1518 if (info->app_info == NULL)
1519 return PMINFO_R_ERROR;
1521 *taskmanage = _get_bool_value(info->app_info->taskmanage);
1525 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
1527 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1528 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1529 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1531 if (info->app_info == NULL)
1532 return PMINFO_R_ERROR;
1534 *enabled = _get_bool_value(info->app_info->enabled);
1539 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
1541 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1542 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1543 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1545 if (info->app_info == NULL)
1546 return PMINFO_R_ERROR;
1548 *onboot = _get_bool_value(info->app_info->onboot);
1552 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
1554 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1555 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1556 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1558 if (info->app_info == NULL)
1559 return PMINFO_R_ERROR;
1561 *autorestart = _get_bool_value(info->app_info->autorestart);
1565 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
1567 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1568 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1569 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1571 if (info->app_info == NULL)
1572 return PMINFO_R_ERROR;
1574 *mainapp = _get_bool_value(info->app_info->mainapp);
1578 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
1580 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1581 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1582 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1584 if (info->app_info == NULL)
1585 return PMINFO_R_ERROR;
1587 *preload = _get_bool_value(info->app_info->preload);
1591 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
1593 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1594 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1595 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1597 if (info->app_info == NULL)
1598 return PMINFO_R_ERROR;
1600 *submode = _get_bool_value(info->app_info->submode);
1604 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
1606 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1607 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
1608 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
1610 category_x *ptr = NULL;
1611 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1613 if (info->app_info == NULL)
1614 return PMINFO_R_ERROR;
1617 for (ptr = info->app_info->category; ptr; ptr = ptr->next) {
1619 if (strcasecmp(ptr->name, category) == 0) {
1629 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
1632 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1634 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
1635 _LOGE("invalid parameter");
1636 return PMINFO_R_EINVAL;
1639 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
1644 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
1646 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1647 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1648 __cleanup_appinfo(info);
1652 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
1654 return (pkgmgrinfo_pkginfo_filter_create(handle));
1657 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
1659 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1662 static gint __compare_func(gconstpointer data1, gconstpointer data2)
1664 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
1665 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
1666 if (node1->prop == node2->prop)
1668 else if (node1->prop > node2->prop)
1674 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
1675 const char *property, const int value)
1677 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1678 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1679 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1681 GSList *link = NULL;
1683 prop = _pminfo_appinfo_convert_to_prop_int(property);
1684 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
1685 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
1686 _LOGE("Invalid Integer Property\n");
1687 return PMINFO_R_EINVAL;
1689 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1690 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1692 _LOGE("Out of Memory!!!\n");
1693 return PMINFO_R_ERROR;
1695 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1696 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1698 _LOGE("Out of Memory\n");
1701 return PMINFO_R_ERROR;
1705 /*If API is called multiple times for same property, we should override the previous values.
1706 Last value set will be used for filtering.*/
1707 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1709 filter->list = g_slist_delete_link(filter->list, link);
1710 filter->list = g_slist_append(filter->list, (gpointer)node);
1715 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
1716 const char *property, const bool value)
1718 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1719 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1721 GSList *link = NULL;
1723 prop = _pminfo_appinfo_convert_to_prop_bool(property);
1724 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
1725 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
1726 _LOGE("Invalid Boolean Property\n");
1727 return PMINFO_R_EINVAL;
1729 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1730 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1732 _LOGE("Out of Memory!!!\n");
1733 return PMINFO_R_ERROR;
1736 val = strndup("('true','True')", 15);
1738 val = strndup("('false','False')", 17);
1740 _LOGE("Out of Memory\n");
1743 return PMINFO_R_ERROR;
1747 /*If API is called multiple times for same property, we should override the previous values.
1748 Last value set will be used for filtering.*/
1749 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1751 filter->list = g_slist_delete_link(filter->list, link);
1752 filter->list = g_slist_append(filter->list, (gpointer)node);
1757 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
1758 const char *property, const char *value)
1760 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1761 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1762 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1764 pkgmgrinfo_node_x *ptr = NULL;
1765 char prev[PKG_STRING_LEN_MAX] = {'\0'};
1766 char temp[PKG_STRING_LEN_MAX] = {'\0'};
1767 GSList *link = NULL;
1769 prop = _pminfo_appinfo_convert_to_prop_str(property);
1770 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
1771 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
1772 _LOGE("Invalid String Property\n");
1773 return PMINFO_R_EINVAL;
1775 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1776 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1778 _LOGE("Out of Memory!!!\n");
1779 return PMINFO_R_ERROR;
1783 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
1784 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
1785 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
1787 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
1789 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1791 filter->list = g_slist_delete_link(filter->list, link);
1792 filter->list = g_slist_append(filter->list, (gpointer)node);
1794 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
1795 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
1796 case E_PMINFO_APPINFO_PROP_APP_URI:
1797 case E_PMINFO_APPINFO_PROP_APP_MIME:
1798 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
1800 _LOGE("Out of Memory\n");
1803 return PMINFO_R_ERROR;
1805 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1807 ptr = (pkgmgrinfo_node_x *)link->data;
1808 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
1809 _LOGE("Previous value is %s\n", prev);
1810 filter->list = g_slist_delete_link(filter->list, link);
1811 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
1812 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1813 _LOGE("New value is %s\n", val);
1815 filter->list = g_slist_append(filter->list, (gpointer)node);
1816 memset(temp, '\0', PKG_STRING_LEN_MAX);
1818 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
1819 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1820 _LOGE("First value is %s\n", val);
1822 filter->list = g_slist_append(filter->list, (gpointer)node);
1823 memset(temp, '\0', PKG_STRING_LEN_MAX);
1827 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
1828 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1830 filter->list = g_slist_delete_link(filter->list, link);
1831 filter->list = g_slist_append(filter->list, (gpointer)node);
1837 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
1839 int *p = (int*)data;
1840 *p = atoi(coltxt[0]);
1841 _LOGE("count value is %d\n", *p);
1845 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
1847 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1848 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1849 char *locale = NULL;
1850 char *condition = NULL;
1851 char *error_message = NULL;
1852 char query[MAX_QUERY_LEN] = {'\0'};
1853 char where[MAX_QUERY_LEN] = {'\0'};
1857 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1858 /*Get current locale*/
1859 locale = _get_system_locale();
1860 if (locale == NULL) {
1861 _LOGE("manifest locale is NULL\n");
1862 return PMINFO_R_ERROR;
1865 ret = __open_manifest_db(uid);
1867 _LOGE("Fail to open manifest DB\n");
1869 return PMINFO_R_ERROR;
1872 /*Start constructing query*/
1873 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
1875 /*Get where clause*/
1876 for (list = filter->list; list; list = g_slist_next(list)) {
1877 __get_filter_condition(list->data, &condition);
1879 strncat(where, condition, sizeof(where) - strlen(where) -1);
1880 where[sizeof(where) - 1] = '\0';
1884 if (g_slist_next(list)) {
1885 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
1886 where[sizeof(where) - 1] = '\0';
1889 if (strlen(where) > 0) {
1890 strncat(query, where, sizeof(query) - strlen(query) - 1);
1891 query[sizeof(query) - 1] = '\0';
1896 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
1897 _LOGE("Don't execute query = %s error message = %s\n", query,
1899 sqlite3_free(error_message);
1900 ret = PMINFO_R_ERROR;
1910 __close_manifest_db();
1914 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
1916 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
1919 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
1920 pkgmgrinfo_appinfo_filter_h handle,
1921 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
1923 if (handle == NULL || app_cb == NULL) {
1924 LOGE("invalid parameter");
1925 return PMINFO_R_EINVAL;
1928 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
1932 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
1933 pkgmgrinfo_app_list_cb app_cb, void * user_data)
1935 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
1938 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
1940 return (pkgmgrinfo_pkginfo_filter_create(handle));
1943 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
1945 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1948 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
1949 const char *key, const char *value)
1951 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
1952 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
1953 /*value can be NULL. In that case all apps with specified key should be displayed*/
1957 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1958 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1959 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
1961 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
1965 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
1968 /*If API is called multiple times, we should OR all conditions.*/
1969 filter->list = g_slist_append(filter->list, (gpointer)node);
1970 /*All memory will be freed in destroy API*/
1988 static void __get_metadata_filter_condition(gpointer data, char **condition)
1990 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
1991 char key[MAX_QUERY_LEN] = {'\0'};
1992 char value[MAX_QUERY_LEN] = {'\0'};
1994 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
1997 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
2002 *condition = strdup(key);
2006 static char *_get_metadata_filtered_query(const char *query_raw,
2007 pkgmgrinfo_filter_x *filter)
2009 char buf[MAX_QUERY_LEN] = { 0, };
2013 GSList *head = NULL;
2016 head = filter->list;
2018 strncat(buf, query_raw, MAX_QUERY_LEN - 1);
2020 for (list = head; list; list = list->next) {
2021 /* TODO: revise condition getter function */
2022 __get_metadata_filter_condition(list->data, &condition);
2023 if (condition == NULL)
2025 if (buf[strlen(query_raw)] == '\0') {
2026 len += strlen(" WHERE ");
2027 strncat(buf, " WHERE ", MAX_QUERY_LEN - len - 1);
2029 len += strlen(" AND ");
2030 strncat(buf, " AND ", MAX_QUERY_LEN -len - 1);
2032 len += strlen(condition);
2033 strncat(buf, condition, sizeof(buf) - len - 1);
2041 static GSList *_appinfo_get_metadata_filtered_list(pkgmgrinfo_filter_x *filter)
2043 static const char query_raw[] =
2044 "SELECT app_id FROM package_app_app_metadata";
2048 GSList *list = NULL;
2051 query = _get_metadata_filtered_query(query_raw, filter);
2052 if (query == NULL) {
2053 LOGE("out of memory");
2057 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
2060 if (ret != SQLITE_OK) {
2061 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
2065 while (sqlite3_step(stmt) == SQLITE_ROW) {
2066 _save_column_str(stmt, 0, (const char **)&appid);
2067 list = g_slist_append(list, appid);
2070 sqlite3_finalize(stmt);
2075 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2076 pkgmgrinfo_appinfo_metadata_filter_h handle,
2077 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2082 pkgmgrinfo_appinfo_h info;
2085 if (handle == NULL || app_cb == NULL) {
2086 LOGE("invalid parameter");
2087 return PMINFO_R_EINVAL;
2090 if (__open_manifest_db(uid) < 0)
2091 return PMINFO_R_ERROR;
2093 list = _appinfo_get_metadata_filtered_list(handle);
2096 __close_manifest_db();
2100 for (tmp = list; tmp; tmp = tmp->next) {
2101 appid = (char *)tmp->data;
2103 if (pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid,
2108 if (app_cb(info, user_data) < 0)
2110 pkgmgrinfo_appinfo_destroy_appinfo(info);
2116 __close_manifest_db();
2121 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
2122 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2124 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, user_data, GLOBAL_USER);
2127 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2130 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2132 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2133 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2135 val = info->uiapp_info->guestmode_visibility;
2136 *status = _get_bool_value(val);