13 #include "pkgmgr-info.h"
14 #include "pkgmgrinfo_debug.h"
15 #include "pkgmgrinfo_private.h"
16 #include "pkgmgr_parser.h"
18 static bool _get_bool_value(const char *str)
22 else if (!strcasecmp(str, "true"))
28 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
30 pkgmgr_appinfo_x *info = data;
31 pkgmgr_appinfo_x *tmp;
33 while (info != NULL) {
36 free((void *)info->package);
38 free((void *)info->locale);
40 pkgmgrinfo_basic_free_application(info->app_info);
47 static char *_get_filtered_query(const char *query_raw,
48 pkgmgrinfo_filter_x *filter)
50 char buf[MAX_QUERY_LEN] = { 0, };
59 strncat(buf, query_raw, MAX_QUERY_LEN - 1);
61 for (list = head; list; list = list->next) {
62 /* TODO: revise condition getter function */
63 __get_filter_condition(list->data, &condition);
64 if (condition == NULL)
66 if (buf[strlen(query_raw)] == '\0') {
67 len += strlen(" WHERE ");
68 strncat(buf, " WHERE ", MAX_QUERY_LEN - len - 1);
70 len += strlen(" AND ");
71 strncat(buf, " AND ", MAX_QUERY_LEN -len - 1);
73 len += strlen(condition);
74 strncat(buf, condition, sizeof(buf) - len - 1);
82 static gint __list_strcmp(gconstpointer a, gconstpointer b)
84 return strcmp((char *)a, (char *)b);
87 static gint _appinfo_get_list(sqlite3 *db, const char *locale,
88 pkgmgrinfo_filter_x *filter, GList **list)
90 static const char query_raw[] =
91 "SELECT DISTINCT package_app_info.app_id FROM package_app_info"
92 " LEFT OUTER JOIN package_app_localized_info"
93 " ON package_app_info.app_id=package_app_localized_info.app_id"
94 " AND package_app_localized_info.app_locale=%Q"
95 " LEFT OUTER JOIN package_app_app_category"
96 " ON package_app_info.app_id=package_app_app_category.app_id"
97 " LEFT OUTER JOIN package_app_app_svc"
98 " ON package_app_info.app_id=package_app_app_svc.app_id "
99 " LEFT OUTER JOIN package_app_app_metadata"
100 " ON package_app_info.app_id=package_app_app_metadata.app_id ";
103 char *query_localized;
107 query = _get_filtered_query(query_raw, filter);
109 return PMINFO_R_ERROR;
110 query_localized = sqlite3_mprintf(query, locale);
112 if (query_localized == NULL)
113 return PMINFO_R_ERROR;
115 ret = sqlite3_prepare_v2(db, query_localized,
116 strlen(query_localized), &stmt, NULL);
117 sqlite3_free(query_localized);
118 if (ret != SQLITE_OK) {
119 LOGE("prepare failed: %s", sqlite3_errmsg(db));
120 return PMINFO_R_ERROR;
123 while (sqlite3_step(stmt) == SQLITE_ROW) {
124 _save_column_str(stmt, 0, (const char **)&appid);
126 *list = g_list_insert_sorted(*list, appid,
130 sqlite3_finalize(stmt);
135 static int _appinfo_get_filtered_list(pkgmgrinfo_filter_x *filter, uid_t uid,
144 locale = _get_system_locale();
146 return PMINFO_R_ERROR;
148 dbpath = getUserPkgParserDBPathUID(uid);
149 if (dbpath == NULL) {
151 return PMINFO_R_ERROR;
154 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
155 if (ret != SQLITE_OK) {
156 _LOGE("failed to open db: %d", ret);
158 return PMINFO_R_ERROR;
161 if (_appinfo_get_list(db, locale, filter, list)) {
163 sqlite3_close_v2(db);
164 return PMINFO_R_ERROR;
166 sqlite3_close_v2(db);
168 if (uid == GLOBAL_USER) {
173 /* search again from global */
174 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
175 if (dbpath == NULL) {
177 return PMINFO_R_ERROR;
180 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
181 if (ret != SQLITE_OK) {
182 _LOGE("failed to open db: %d", ret);
184 return PMINFO_R_ERROR;
187 if (_appinfo_get_list(db, locale, filter, list)) {
189 sqlite3_close_v2(db);
190 return PMINFO_R_ERROR;
192 sqlite3_close_v2(db);
194 /* remove duplicate element:
195 * since the list is sorted, we can remove duplicates in linear time
197 for (tmp = *list; tmp; tmp = tmp->next) {
198 if (tmp->prev == NULL || tmp->data == NULL)
200 if (strcmp((const char *)tmp->prev->data,
201 (const char *)tmp->data) == 0)
202 *list = g_list_delete_link(*list, tmp);
209 static int _appinfo_get_label(sqlite3 *db, const char *appid,
210 const char *locale, label_x **label)
212 static const char query_raw[] =
213 "SELECT app_label, app_locale "
214 "FROM package_app_localized_info "
215 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
222 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
224 LOGE("out of memory");
225 return PMINFO_R_ERROR;
228 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
230 if (ret != SQLITE_OK) {
231 LOGE("prepare failed: %s", sqlite3_errmsg(db));
232 return PMINFO_R_ERROR;
235 while (sqlite3_step(stmt) == SQLITE_ROW) {
236 info = calloc(1, sizeof(label_x));
238 LOGE("out of memory");
239 sqlite3_finalize(stmt);
241 LISTHEAD(*label, info);
244 return PMINFO_R_ERROR;
247 _save_column_str(stmt, idx++, &info->text);
248 _save_column_str(stmt, idx++, &info->lang);
249 LISTADD(*label, info);
253 LISTHEAD(*label, info);
257 sqlite3_finalize(stmt);
262 static int _appinfo_get_icon(sqlite3 *db, const char *appid, const char *locale,
265 static const char query_raw[] =
266 "SELECT app_icon, app_locale "
267 "FROM package_app_localized_info "
268 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
275 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
277 LOGE("out of memory");
278 return PMINFO_R_ERROR;
281 ret = sqlite3_prepare_v2(db, query, strlen(query),
284 if (ret != SQLITE_OK) {
285 LOGE("prepare failed: %s", sqlite3_errmsg(db));
286 return PMINFO_R_ERROR;
289 while (sqlite3_step(stmt) == SQLITE_ROW) {
290 info = calloc(1, sizeof(icon_x));
292 LOGE("out of memory");
293 sqlite3_finalize(stmt);
295 LISTHEAD(*icon, info);
298 return PMINFO_R_ERROR;
301 _save_column_str(stmt, idx++, &info->text);
302 _save_column_str(stmt, idx++, &info->lang);
303 LISTADD(*icon, info);
307 LISTHEAD(*icon, info);
311 sqlite3_finalize(stmt);
316 static int _appinfo_get_category(sqlite3 *db, const char *appid,
317 category_x **category)
319 static const char query_raw[] =
320 "SELECT category FROM package_app_app_category WHERE app_id=%Q";
326 query = sqlite3_mprintf(query_raw, appid);
328 LOGE("out of memory");
329 return PMINFO_R_ERROR;
332 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
334 if (ret != SQLITE_OK) {
335 LOGE("prepare failed: %s", sqlite3_errmsg(db));
336 return PMINFO_R_ERROR;
339 while (sqlite3_step(stmt) == SQLITE_ROW) {
340 info = calloc(1, sizeof(category_x));
342 LOGE("out of memory");
343 sqlite3_finalize(stmt);
345 LISTHEAD(*category, info);
348 return PMINFO_R_ERROR;
350 _save_column_str(stmt, 0, &info->name);
351 LISTADD(*category, info);
355 LISTHEAD(*category, info);
359 sqlite3_finalize(stmt);
364 static void __parse_appcontrol(appcontrol_x **appcontrol, char *appcontrol_str)
371 if (appcontrol_str == NULL)
374 dup = strdup(appcontrol_str);
376 ac = calloc(1, sizeof(appcontrol_x));
378 _LOGE("out of memory");
381 token = strtok_r(dup, "|", &ptr);
382 if (token && strcmp(token, "NULL"))
383 ac->operation = strdup(token);
384 token = strtok_r(NULL, "|", &ptr);
385 if (token && strcmp(token, "NULL"))
386 ac->uri = strdup(token);
387 token = strtok_r(NULL, "|", &ptr);
388 if (token && strcmp(token, "NULL"))
389 ac->mime = strdup(token);
390 LISTADD(*appcontrol, ac);
391 } while ((token = strtok_r(NULL, ";", &ptr)));
394 LISTHEAD(*appcontrol, ac);
400 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
401 appcontrol_x **appcontrol)
403 static const char query_raw[] =
404 "SELECT app_control FROM package_app_app_control "
409 appcontrol_x *info = NULL;
412 query = sqlite3_mprintf(query_raw, appid);
414 LOGE("out of memory");
415 return PMINFO_R_ERROR;
418 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
420 if (ret != SQLITE_OK) {
421 LOGE("prepare failed: %s", sqlite3_errmsg(db));
422 return PMINFO_R_ERROR;
425 while (sqlite3_step(stmt) == SQLITE_ROW) {
427 _save_column_str(stmt, 0, (const char **)&str);
429 __parse_appcontrol(&info, str);
435 sqlite3_finalize(stmt);
440 static int _appinfo_get_data_control(sqlite3 *db, const char *appid,
441 datacontrol_x **datacontrol)
443 static const char query_raw[] =
444 "SELECT providerid, access, type "
445 "FROM package_app_data_control WHERE app_id=%Q";
452 query = sqlite3_mprintf(query_raw, appid);
454 LOGE("out of memory");
455 return PMINFO_R_ERROR;
458 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
460 if (ret != SQLITE_OK) {
461 LOGE("prepare failed: %s", sqlite3_errmsg(db));
462 return PMINFO_R_ERROR;
465 while (sqlite3_step(stmt) == SQLITE_ROW) {
466 info = calloc(1, sizeof(datacontrol_x));
468 LOGE("out of memory");
469 sqlite3_finalize(stmt);
471 LISTHEAD(*datacontrol, info);
474 return PMINFO_R_ERROR;
477 _save_column_str(stmt, idx++, &info->providerid);
478 _save_column_str(stmt, idx++, &info->access);
479 _save_column_str(stmt, idx++, &info->type);
480 LISTADD(*datacontrol, info);
484 LISTHEAD(*datacontrol, info);
488 sqlite3_finalize(stmt);
493 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
494 metadata_x **metadata)
496 static const char query_raw[] =
497 "SELECT md_key, md_value "
498 "FROM package_app_app_metadata WHERE app_id=%Q";
505 query = sqlite3_mprintf(query_raw, appid);
507 LOGE("out of memory");
508 return PMINFO_R_ERROR;
511 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
513 if (ret != SQLITE_OK) {
514 LOGE("prepare failed: %s", sqlite3_errmsg(db));
515 return PMINFO_R_ERROR;
518 while (sqlite3_step(stmt) == SQLITE_ROW) {
519 info = calloc(1, sizeof(metadata_x));
521 LOGE("out of memory");
522 sqlite3_finalize(stmt);
524 LISTHEAD(*metadata, info);
527 return PMINFO_R_ERROR;
530 _save_column_str(stmt, idx++, &info->key);
531 _save_column_str(stmt, idx++, &info->value);
532 LISTADD(*metadata, info);
536 LISTHEAD(*metadata, info);
540 sqlite3_finalize(stmt);
546 static int _appinfo_get_application(sqlite3 *db, const char *appid,
547 const char *locale, application_x **application)
549 static const char query_raw[] =
550 "SELECT app_id, app_component, app_exec, app_nodisplay, "
551 "app_type, app_onboot, app_multiple, app_autorestart, "
552 "app_taskmanage, app_enabled, app_hwacceleration, "
553 "app_screenreader, app_mainapp, app_recentimage, "
554 "app_launchcondition, app_indicatordisplay, app_portraitimg, "
555 "app_landscapeimg, app_guestmodevisibility, "
556 "app_permissiontype, app_preload, app_submode, "
557 "app_submode_mainid, app_launch_mode, app_ui_gadget, "
558 "app_support_disable, "
559 "component_type, package "
560 "FROM package_app_info WHERE app_id=%Q";
567 query = sqlite3_mprintf(query_raw, appid);
569 LOGE("out of memory");
570 return PMINFO_R_ERROR;
573 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
575 if (ret != SQLITE_OK) {
576 LOGE("prepare failed: %s", sqlite3_errmsg(db));
577 return PMINFO_R_ERROR;
580 ret = sqlite3_step(stmt);
581 if (ret == SQLITE_DONE) {
582 sqlite3_finalize(stmt);
583 return PMINFO_R_ENOENT;
584 } else if (ret != SQLITE_ROW) {
585 LOGE("step failed: %s", sqlite3_errmsg(db));
586 sqlite3_finalize(stmt);
587 return PMINFO_R_ERROR;
590 info = calloc(1, sizeof(application_x));
592 LOGE("out of memory");
593 sqlite3_finalize(stmt);
594 return PMINFO_R_ERROR;
597 _save_column_str(stmt, idx++, &info->appid);
598 _save_column_str(stmt, idx++, &info->component);
599 _save_column_str(stmt, idx++, &info->exec);
600 _save_column_str(stmt, idx++, &info->nodisplay);
601 _save_column_str(stmt, idx++, &info->type);
602 _save_column_str(stmt, idx++, &info->onboot);
603 _save_column_str(stmt, idx++, &info->multiple);
604 _save_column_str(stmt, idx++, &info->autorestart);
605 _save_column_str(stmt, idx++, &info->taskmanage);
606 _save_column_str(stmt, idx++, &info->enabled);
607 _save_column_str(stmt, idx++, &info->hwacceleration);
608 _save_column_str(stmt, idx++, &info->screenreader);
609 _save_column_str(stmt, idx++, &info->mainapp);
610 _save_column_str(stmt, idx++, &info->recentimage);
611 _save_column_str(stmt, idx++, &info->launchcondition);
612 _save_column_str(stmt, idx++, &info->indicatordisplay);
613 _save_column_str(stmt, idx++, &info->portraitimg);
614 _save_column_str(stmt, idx++, &info->landscapeimg);
615 _save_column_str(stmt, idx++, &info->guestmode_visibility);
616 _save_column_str(stmt, idx++, &info->permission_type);
617 _save_column_str(stmt, idx++, &info->preload);
618 _save_column_str(stmt, idx++, &info->submode);
619 _save_column_str(stmt, idx++, &info->submode_mainid);
620 _save_column_str(stmt, idx++, &info->launch_mode);
621 _save_column_str(stmt, idx++, &info->ui_gadget);
622 _save_column_str(stmt, idx++, &info->support_disable);
623 _save_column_str(stmt, idx++, &info->component_type);
624 _save_column_str(stmt, idx++, &info->package);
626 if (_appinfo_get_label(db, info->appid, locale, &info->label)) {
627 pkgmgrinfo_basic_free_application(info);
628 sqlite3_finalize(stmt);
629 return PMINFO_R_ERROR;
632 if (_appinfo_get_icon(db, info->appid, locale, &info->icon)) {
633 pkgmgrinfo_basic_free_application(info);
634 sqlite3_finalize(stmt);
635 return PMINFO_R_ERROR;
638 if (_appinfo_get_category(db, info->appid, &info->category)) {
639 pkgmgrinfo_basic_free_application(info);
640 sqlite3_finalize(stmt);
641 return PMINFO_R_ERROR;
644 if (_appinfo_get_app_control(db, info->appid, &info->appcontrol)) {
645 pkgmgrinfo_basic_free_application(info);
646 sqlite3_finalize(stmt);
647 return PMINFO_R_ERROR;
650 if (_appinfo_get_data_control(db, info->appid, &info->datacontrol)) {
651 pkgmgrinfo_basic_free_application(info);
652 sqlite3_finalize(stmt);
653 return PMINFO_R_ERROR;
656 if (_appinfo_get_metadata(db, info->appid, &info->metadata)) {
657 pkgmgrinfo_basic_free_application(info);
658 sqlite3_finalize(stmt);
659 return PMINFO_R_ERROR;
664 sqlite3_finalize(stmt);
669 static int _appinfo_get_appinfo(const char *appid, uid_t uid,
670 pkgmgr_appinfo_x **appinfo)
676 pkgmgr_appinfo_x *info;
678 dbpath = getUserPkgParserDBPathUID(uid);
680 return PMINFO_R_ERROR;
682 locale = _get_system_locale();
684 return PMINFO_R_ERROR;
686 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
687 if (ret != SQLITE_OK) {
688 _LOGE("failed to open db: %d", ret);
690 return PMINFO_R_ERROR;
693 info = calloc(1, sizeof(pkgmgr_appinfo_x));
695 _LOGE("out of memory");
697 sqlite3_close_v2(db);
698 return PMINFO_R_ERROR;
701 ret = _appinfo_get_application(db, appid, locale, &info->app_info);
702 if (ret == PMINFO_R_OK) {
703 info->locale = strdup(locale);
704 info->package = strdup(info->app_info->package);
710 sqlite3_close_v2(db);
715 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
716 pkgmgrinfo_appinfo_h *handle)
720 if (appid == NULL || handle == NULL) {
721 LOGE("invalid parameter");
722 return PMINFO_R_EINVAL;
725 ret = _appinfo_get_appinfo(appid, uid, (pkgmgr_appinfo_x **)handle);
726 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
727 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
728 (pkgmgr_appinfo_x **)handle);
730 if (ret != PMINFO_R_OK)
731 _LOGE("failed to get appinfo of %s for user %d", appid, uid);
736 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
738 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
741 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
742 pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb,
746 pkgmgr_appinfo_x *info;
752 ret = _appinfo_get_filtered_list(filter, uid, &list);
753 if (ret != PMINFO_R_OK)
754 return PMINFO_R_ERROR;
756 for (tmp = list; tmp; tmp = tmp->next) {
757 appid = (char *)tmp->data;
759 ret = _appinfo_get_appinfo(appid, uid, &info);
760 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
761 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
763 if (ret != PMINFO_R_OK) {
767 if (app_list_cb(info, user_data) < 0)
769 pkgmgrinfo_appinfo_destroy_appinfo(info);
779 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
780 pkgmgrinfo_app_component component,
781 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
784 pkgmgrinfo_appinfo_filter_h filter;
786 const char *comp_str = NULL;
788 if (handle == NULL || app_func == NULL) {
789 LOGE("invalied parameter");
790 return PMINFO_R_EINVAL;
793 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
794 LOGE("invalid parameter");
795 return PMINFO_R_EINVAL;
798 if (pkgmgrinfo_appinfo_filter_create(&filter))
799 return PMINFO_R_ERROR;
801 if (pkgmgrinfo_appinfo_filter_add_string(filter,
802 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
803 pkgmgrinfo_appinfo_filter_destroy(filter);
804 return PMINFO_R_ERROR;
810 comp_str = PMINFO_APPINFO_UI_APP;
813 comp_str = PMINFO_APPINFO_SVC_APP;
820 if (pkgmgrinfo_appinfo_filter_add_string(filter,
821 PMINFO_APPINFO_PROP_APP_COMPONENT,
823 pkgmgrinfo_appinfo_filter_destroy(filter);
824 return PMINFO_R_ERROR;
828 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, app_func,
831 pkgmgrinfo_appinfo_filter_destroy(filter);
836 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
837 pkgmgrinfo_app_list_cb app_func, void *user_data)
839 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
842 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
844 if (app_func == NULL) {
845 LOGE("invalid parameter");
846 return PMINFO_R_EINVAL;
849 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
853 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
855 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
858 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
860 if (app_func == NULL) {
861 LOGE("invalid parameter");
862 return PMINFO_R_EINVAL;
865 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
869 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
871 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
874 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
876 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
878 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
879 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
881 if (info->app_info == NULL || info->app_info->appid == NULL)
882 return PMINFO_R_ERROR;
883 *appid = (char *)info->app_info->appid;
888 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
890 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
892 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
893 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
895 if (info->package == NULL)
896 return PMINFO_R_ERROR;
898 *pkg_name = (char *)info->package;
903 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
905 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
907 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
908 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
910 if (info->package == NULL)
911 return PMINFO_R_ERROR;
913 *pkgid = (char *)info->package;
918 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
920 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
922 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
923 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
925 if (info->app_info == NULL || info->app_info->exec == NULL)
926 return PMINFO_R_ERROR;
927 *exec = (char *)info->app_info->exec;
933 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
938 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
940 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
941 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
943 locale = info->locale;
944 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
946 start = info->app_info->icon;
947 for (ptr = start; ptr != NULL; ptr = ptr->next) {
948 if (ptr->lang == NULL)
951 if (strcmp(ptr->lang, locale) == 0) {
952 *icon = (char *)ptr->text;
953 if (strcasecmp(*icon, "(null)") == 0) {
954 locale = DEFAULT_LOCALE;
959 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
960 *icon = (char *)ptr->text;
965 return PMINFO_R_ERROR;
969 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
974 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
976 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
977 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
979 locale = info->locale;
980 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
982 start = info->app_info->label;
983 for (ptr = start; ptr != NULL; ptr = ptr->next) {
984 if (ptr->lang == NULL)
987 if (strcmp(ptr->lang, locale) == 0) {
988 *label = (char *)ptr->text;
989 if (strcasecmp(*label, "(null)") == 0) {
990 locale = DEFAULT_LOCALE;
995 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
996 *label = (char *)ptr->text;
1001 return PMINFO_R_ERROR;
1004 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1006 char *result = NULL;
1008 sqlite3_stmt *stmt = NULL;
1011 const char *manifest_db;
1013 manifest_db = getUserPkgParserDBPathUID(uid);
1014 if (manifest_db == NULL) {
1015 _LOGE("Failed to get manifest db path");
1019 if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
1020 _LOGE("DB open fail\n");
1024 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1025 if (query == NULL) {
1026 _LOGE("Out of memory");
1030 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1031 _LOGE("prepare_v2 fail\n");
1035 if (sqlite3_step(stmt) == SQLITE_ROW) {
1036 val = (char *)sqlite3_column_text(stmt, 0);
1038 result = strdup(val);
1042 sqlite3_finalize(stmt);
1043 sqlite3_free(query);
1049 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1053 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1055 val = _get_localed_label(appid, locale, uid);
1057 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1060 return PMINFO_R_ERROR;
1067 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1069 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
1072 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1074 if ( strcasecmp(comp, "uiapp") == 0)
1075 return PMINFO_UI_APP;
1076 else if ( strcasecmp(comp, "svcapp") == 0)
1077 return PMINFO_SVC_APP;
1082 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1084 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1087 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1088 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1090 if (info->app_info == NULL)
1091 return PMINFO_R_ERROR;
1093 comp = __appcomponent_convert(info->app_info->component);
1095 return PMINFO_R_ERROR;
1102 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1104 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1106 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1107 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1109 if (info->app_info == NULL || info->app_info->type == NULL)
1110 return PMINFO_R_ERROR;
1111 *app_type = (char *)info->app_info->type;
1116 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
1117 int *operation_count, char ***operation)
1119 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1120 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1121 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1122 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1123 *operation_count = data->operation_count;
1124 *operation = data->operation;
1128 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
1129 int *uri_count, char ***uri)
1131 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1132 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1133 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1134 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1135 *uri_count = data->uri_count;
1140 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
1141 int *mime_count, char ***mime)
1143 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1144 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1145 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1146 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1147 *mime_count = data->mime_count;
1152 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1153 int *subapp_count, char ***subapp)
1155 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1156 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1157 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1158 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1159 *subapp_count = data->subapp_count;
1160 *subapp = data->subapp;
1164 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1168 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1170 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1171 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1173 for (ptr = info->app_info->icon; ptr != NULL; ptr = ptr->next) {
1174 if (ptr->section == NULL)
1177 val = (char *)ptr->section;
1178 if (val && strcmp(val, "setting") == 0) {
1179 *icon = (char *)ptr->text;
1184 return PMINFO_R_ERROR;
1188 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1192 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1194 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1195 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1197 for (ptr = info->app_info->icon; ptr != NULL; ptr = ptr->next) {
1198 if (ptr->section == NULL)
1201 val = (char *)ptr->section;
1202 if (val && strcmp(val, "notification") == 0){
1203 *icon = (char *)ptr->text;
1208 return PMINFO_R_ERROR;
1211 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1214 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1216 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1217 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1219 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1220 return PMINFO_R_ERROR;
1222 val = (char *)info->app_info->recentimage;
1223 if (strcasecmp(val, "capture") == 0)
1224 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1225 else if (strcasecmp(val, "icon") == 0)
1226 *type = PMINFO_RECENTIMAGE_USE_ICON;
1228 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1233 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1237 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1239 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1240 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1242 for (ptr = info->app_info->image; ptr != NULL; ptr = ptr->next) {
1243 if (ptr->section == NULL)
1246 val = (char *)ptr->section;
1247 if (val && strcmp(val, "preview") == 0) {
1248 *preview_img = (char *)ptr->text;
1253 return PMINFO_R_ERROR;
1256 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1259 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1261 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1262 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1264 val = info->app_info->permission_type;
1266 return PMINFO_R_ERROR;
1268 if (strcmp(val, "signature") == 0)
1269 *permission = PMINFO_PERMISSION_SIGNATURE;
1270 else if (strcmp(val, "privilege") == 0)
1271 *permission = PMINFO_PERMISSION_PRIVILEGE;
1273 *permission = PMINFO_PERMISSION_NORMAL;
1278 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1280 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1282 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1283 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1285 if (info->app_info == NULL || info->app_info->component_type == NULL)
1286 return PMINFO_R_ERROR;
1288 *component_type = (char *)info->app_info->component_type;
1293 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1296 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1298 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1299 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1301 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1302 return PMINFO_R_ERROR;
1304 val = (char *)info->app_info->hwacceleration;
1305 if (strcasecmp(val, "not-use-GL") == 0)
1306 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
1307 else if (strcasecmp(val, "use-GL") == 0)
1308 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
1310 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
1315 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1318 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1320 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1321 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1323 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1324 return PMINFO_R_ERROR;
1326 val = (char *)info->app_info->screenreader;
1327 if (strcasecmp(val, "screenreader-off") == 0)
1328 *screenreader = PMINFO_SCREENREADER_OFF;
1329 else if (strcasecmp(val, "screenreader-on") == 0)
1330 *screenreader = PMINFO_SCREENREADER_ON;
1332 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1337 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1339 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1341 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1342 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1343 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1345 if (info->app_info == NULL || info->app_info->portraitimg ||
1346 info->app_info->landscapeimg == NULL)
1347 return PMINFO_R_ERROR;
1349 *portrait_img = (char *)info->app_info->portraitimg;
1350 *landscape_img = (char *)info->app_info->landscapeimg;
1355 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
1357 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1359 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1360 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1362 if (info->app_info == NULL || info->app_info->submode_mainid == NULL)
1363 return PMINFO_R_ERROR;
1365 *submode_mainid = (char *)info->app_info->submode_mainid;
1370 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
1372 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1374 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1375 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1377 if (info->app_info->launch_mode == NULL)
1378 return PMINFO_R_ERROR;
1380 *mode = (char *)(info->app_info->launch_mode);
1385 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
1387 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1388 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1389 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1390 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1392 int ret = PMINFO_R_OK;
1394 sqlite3_stmt *stmt = NULL;
1397 ret = __open_manifest_db(uid, true);
1398 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1400 /*Start constructing query*/
1401 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
1404 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1405 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1408 ret = sqlite3_step(stmt);
1409 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1411 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1412 *access = strdup((char *)sqlite3_column_text(stmt, 2));
1417 sqlite3_free(query);
1418 sqlite3_finalize(stmt);
1419 __close_manifest_db();
1423 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
1425 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
1428 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
1430 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1431 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1433 int ret = PMINFO_R_OK;
1435 sqlite3_stmt *stmt = NULL;
1438 ret = __open_manifest_db(uid, true);
1439 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1441 /*Start constructing query*/
1442 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
1445 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1446 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1449 ret = sqlite3_step(stmt);
1450 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1452 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1457 sqlite3_free(query);
1458 sqlite3_finalize(stmt);
1459 __close_manifest_db();
1463 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1465 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
1468 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
1469 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
1471 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1472 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1474 permission_x *ptr = NULL;
1475 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1477 if (info->app_info == NULL)
1478 return PMINFO_R_ERROR;
1480 for (ptr = info->app_info->permission; ptr; ptr = ptr->next) {
1482 ret = permission_func(ptr->value, user_data);
1490 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
1491 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
1493 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1494 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1496 category_x *ptr = NULL;
1497 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1499 if (info->app_info == NULL)
1500 return PMINFO_R_ERROR;
1502 for (ptr = info->app_info->category; ptr; ptr = ptr->next) {
1504 ret = category_func(ptr->name, user_data);
1512 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
1513 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
1515 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1516 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1518 metadata_x *ptr = NULL;
1519 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1521 if (info->app_info == NULL)
1522 return PMINFO_R_ERROR;
1524 for (ptr = info->app_info->metadata; ptr; ptr = ptr->next) {
1526 ret = metadata_func(ptr->key, ptr->value, user_data);
1534 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
1535 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1537 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1538 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1540 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1541 appcontrol_x *appcontrol;
1543 if (info->uiapp_info == NULL)
1544 return PMINFO_R_ERROR;
1546 for (appcontrol = info->app_info->appcontrol; appcontrol; appcontrol = appcontrol->next) {
1547 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1555 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
1557 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1558 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1559 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1561 if (info->app_info == NULL)
1562 return PMINFO_R_ERROR;
1564 *nodisplay = _get_bool_value(info->app_info->nodisplay);
1568 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
1570 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1571 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1572 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1574 if (info->app_info == NULL)
1575 return PMINFO_R_ERROR;
1577 *multiple = _get_bool_value(info->app_info->multiple);
1581 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
1583 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1584 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1585 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1587 if (info->app_info == NULL)
1588 return PMINFO_R_ERROR;
1590 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
1594 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
1596 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1597 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1598 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1600 if (info->app_info == NULL)
1601 return PMINFO_R_ERROR;
1603 *taskmanage = _get_bool_value(info->app_info->taskmanage);
1607 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
1609 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1610 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1611 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1613 if (info->app_info == NULL)
1614 return PMINFO_R_ERROR;
1616 *enabled = _get_bool_value(info->app_info->enabled);
1621 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
1623 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1624 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1625 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1627 if (info->app_info == NULL)
1628 return PMINFO_R_ERROR;
1630 *onboot = _get_bool_value(info->app_info->onboot);
1634 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
1636 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1637 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1638 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1640 if (info->app_info == NULL)
1641 return PMINFO_R_ERROR;
1643 *autorestart = _get_bool_value(info->app_info->autorestart);
1647 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
1649 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1650 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1651 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1653 if (info->app_info == NULL)
1654 return PMINFO_R_ERROR;
1656 *mainapp = _get_bool_value(info->app_info->mainapp);
1660 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
1662 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1663 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1664 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1666 if (info->app_info == NULL)
1667 return PMINFO_R_ERROR;
1669 *preload = _get_bool_value(info->app_info->preload);
1673 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
1675 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1676 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1677 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1679 if (info->app_info == NULL)
1680 return PMINFO_R_ERROR;
1682 *submode = _get_bool_value(info->app_info->submode);
1686 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
1688 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1689 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
1690 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
1692 category_x *ptr = NULL;
1693 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1695 if (info->app_info == NULL)
1696 return PMINFO_R_ERROR;
1699 for (ptr = info->app_info->category; ptr; ptr = ptr->next) {
1701 if (strcasecmp(ptr->name, category) == 0) {
1711 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
1714 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1716 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
1717 _LOGE("invalid parameter");
1718 return PMINFO_R_EINVAL;
1721 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
1726 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
1727 bool *support_disable)
1729 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1731 if (info == NULL || info->app_info == NULL || support_disable == NULL) {
1732 _LOGE("invalid parameter");
1733 return PMINFO_R_EINVAL;
1736 *support_disable = _get_bool_value(info->app_info->support_disable);
1741 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
1743 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1744 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1745 __cleanup_appinfo(info);
1749 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
1751 return (pkgmgrinfo_pkginfo_filter_create(handle));
1754 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
1756 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1759 static gint __compare_func(gconstpointer data1, gconstpointer data2)
1761 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
1762 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
1763 if (node1->prop == node2->prop)
1765 else if (node1->prop > node2->prop)
1771 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
1772 const char *property, const int value)
1774 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1775 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1776 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1778 GSList *link = NULL;
1780 prop = _pminfo_appinfo_convert_to_prop_int(property);
1781 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
1782 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
1783 _LOGE("Invalid Integer Property\n");
1784 return PMINFO_R_EINVAL;
1786 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1787 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1789 _LOGE("Out of Memory!!!\n");
1790 return PMINFO_R_ERROR;
1792 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1793 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1795 _LOGE("Out of Memory\n");
1798 return PMINFO_R_ERROR;
1802 /*If API is called multiple times for same property, we should override the previous values.
1803 Last value set will be used for filtering.*/
1804 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1806 filter->list = g_slist_delete_link(filter->list, link);
1807 filter->list = g_slist_append(filter->list, (gpointer)node);
1812 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
1813 const char *property, const bool value)
1815 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1816 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1818 GSList *link = NULL;
1820 prop = _pminfo_appinfo_convert_to_prop_bool(property);
1821 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
1822 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
1823 _LOGE("Invalid Boolean Property\n");
1824 return PMINFO_R_EINVAL;
1826 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1827 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1829 _LOGE("Out of Memory!!!\n");
1830 return PMINFO_R_ERROR;
1833 val = strndup("('true','True')", 15);
1835 val = strndup("('false','False')", 17);
1837 _LOGE("Out of Memory\n");
1840 return PMINFO_R_ERROR;
1844 /*If API is called multiple times for same property, we should override the previous values.
1845 Last value set will be used for filtering.*/
1846 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1848 filter->list = g_slist_delete_link(filter->list, link);
1849 filter->list = g_slist_append(filter->list, (gpointer)node);
1854 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
1855 const char *property, const char *value)
1857 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1858 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1859 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1861 pkgmgrinfo_node_x *ptr = NULL;
1862 char prev[PKG_STRING_LEN_MAX] = {'\0'};
1863 char temp[PKG_STRING_LEN_MAX] = {'\0'};
1864 GSList *link = NULL;
1866 prop = _pminfo_appinfo_convert_to_prop_str(property);
1867 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
1868 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
1869 _LOGE("Invalid String Property\n");
1870 return PMINFO_R_EINVAL;
1872 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1873 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1875 _LOGE("Out of Memory!!!\n");
1876 return PMINFO_R_ERROR;
1880 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
1881 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
1882 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
1884 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
1886 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1888 filter->list = g_slist_delete_link(filter->list, link);
1889 filter->list = g_slist_append(filter->list, (gpointer)node);
1891 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
1892 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
1893 case E_PMINFO_APPINFO_PROP_APP_URI:
1894 case E_PMINFO_APPINFO_PROP_APP_MIME:
1895 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
1897 _LOGE("Out of Memory\n");
1900 return PMINFO_R_ERROR;
1902 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1904 ptr = (pkgmgrinfo_node_x *)link->data;
1905 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
1906 _LOGE("Previous value is %s\n", prev);
1907 filter->list = g_slist_delete_link(filter->list, link);
1908 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
1909 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1910 _LOGE("New value is %s\n", val);
1912 filter->list = g_slist_append(filter->list, (gpointer)node);
1913 memset(temp, '\0', PKG_STRING_LEN_MAX);
1915 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
1916 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1917 _LOGE("First value is %s\n", val);
1919 filter->list = g_slist_append(filter->list, (gpointer)node);
1920 memset(temp, '\0', PKG_STRING_LEN_MAX);
1924 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
1925 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1927 filter->list = g_slist_delete_link(filter->list, link);
1928 filter->list = g_slist_append(filter->list, (gpointer)node);
1934 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
1939 if (handle == NULL || count == NULL) {
1940 _LOGE("invalid parameter");
1941 return PMINFO_R_EINVAL;
1944 ret = _appinfo_get_filtered_list(handle, uid, &list);
1945 if (ret != PMINFO_R_OK)
1946 return PMINFO_R_ERROR;
1948 *count = g_list_length(list);
1950 g_list_free_full(list, free);
1955 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
1957 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
1960 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
1961 pkgmgrinfo_appinfo_filter_h handle,
1962 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
1964 if (handle == NULL || app_cb == NULL) {
1965 LOGE("invalid parameter");
1966 return PMINFO_R_EINVAL;
1969 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
1973 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
1974 pkgmgrinfo_app_list_cb app_cb, void * user_data)
1976 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
1979 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
1981 return (pkgmgrinfo_pkginfo_filter_create(handle));
1984 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
1986 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1989 API int pkgmgrinfo_appinfo_metadata_filter_add(
1990 pkgmgrinfo_appinfo_metadata_filter_h handle,
1991 const char *key, const char *value)
1995 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
1996 PMINFO_APPINFO_PROP_APP_METADATA_KEY, key);
1997 if (ret != PMINFO_R_OK)
2000 /* value can be NULL.
2001 * In that case all apps with specified key should be displayed
2004 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2005 PMINFO_APPINFO_PROP_APP_METADATA_VALUE, value);
2006 if (ret != PMINFO_R_OK)
2013 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2014 pkgmgrinfo_appinfo_metadata_filter_h handle,
2015 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2017 if (handle == NULL || app_cb == NULL) {
2018 LOGE("invalid parameter");
2019 return PMINFO_R_EINVAL;
2022 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2026 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
2027 pkgmgrinfo_appinfo_metadata_filter_h handle,
2028 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2030 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
2031 user_data, GLOBAL_USER);
2034 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2037 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2039 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2040 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2042 val = info->uiapp_info->guestmode_visibility;
2043 *status = _get_bool_value(val);