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,
145 locale = _get_system_locale();
147 return PMINFO_R_ERROR;
149 dbpath = getUserPkgParserDBPathUID(uid);
150 if (dbpath == NULL) {
152 return PMINFO_R_ERROR;
155 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
156 if (ret != SQLITE_OK) {
157 _LOGE("failed to open db: %d", ret);
159 return PMINFO_R_ERROR;
162 if (_appinfo_get_list(db, locale, filter, list)) {
164 sqlite3_close_v2(db);
165 return PMINFO_R_ERROR;
167 sqlite3_close_v2(db);
169 if (uid == GLOBAL_USER) {
174 /* search again from global */
175 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
176 if (dbpath == NULL) {
178 return PMINFO_R_ERROR;
181 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
182 if (ret != SQLITE_OK) {
183 _LOGE("failed to open db: %d", ret);
185 return PMINFO_R_ERROR;
188 if (_appinfo_get_list(db, locale, filter, list)) {
190 sqlite3_close_v2(db);
191 return PMINFO_R_ERROR;
193 sqlite3_close_v2(db);
195 /* remove duplicate element:
196 * since the list is sorted, we can remove duplicates in linear time
198 for (tmp = *list, tmp2 = g_list_next(tmp); tmp;
199 tmp = tmp2, tmp2 = g_list_next(tmp)) {
200 if (tmp->prev == NULL || tmp->data == NULL)
202 if (strcmp((const char *)tmp->prev->data,
203 (const char *)tmp->data) == 0)
204 *list = g_list_delete_link(*list, tmp);
212 static int _appinfo_get_label(sqlite3 *db, const char *appid,
213 const char *locale, label_x **label)
215 static const char query_raw[] =
216 "SELECT app_label, app_locale "
217 "FROM package_app_localized_info "
218 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
225 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
227 LOGE("out of memory");
228 return PMINFO_R_ERROR;
231 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
233 if (ret != SQLITE_OK) {
234 LOGE("prepare failed: %s", sqlite3_errmsg(db));
235 return PMINFO_R_ERROR;
238 while (sqlite3_step(stmt) == SQLITE_ROW) {
239 info = calloc(1, sizeof(label_x));
241 LOGE("out of memory");
242 sqlite3_finalize(stmt);
244 LISTHEAD(*label, info);
247 return PMINFO_R_ERROR;
250 _save_column_str(stmt, idx++, &info->text);
251 _save_column_str(stmt, idx++, &info->lang);
252 LISTADD(*label, info);
256 LISTHEAD(*label, info);
260 sqlite3_finalize(stmt);
265 static int _appinfo_get_icon(sqlite3 *db, const char *appid, const char *locale,
268 static const char query_raw[] =
269 "SELECT app_icon, app_locale "
270 "FROM package_app_localized_info "
271 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
278 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
280 LOGE("out of memory");
281 return PMINFO_R_ERROR;
284 ret = sqlite3_prepare_v2(db, query, strlen(query),
287 if (ret != SQLITE_OK) {
288 LOGE("prepare failed: %s", sqlite3_errmsg(db));
289 return PMINFO_R_ERROR;
292 while (sqlite3_step(stmt) == SQLITE_ROW) {
293 info = calloc(1, sizeof(icon_x));
295 LOGE("out of memory");
296 sqlite3_finalize(stmt);
298 LISTHEAD(*icon, info);
301 return PMINFO_R_ERROR;
304 _save_column_str(stmt, idx++, &info->text);
305 _save_column_str(stmt, idx++, &info->lang);
306 LISTADD(*icon, info);
310 LISTHEAD(*icon, info);
314 sqlite3_finalize(stmt);
319 static int _appinfo_get_category(sqlite3 *db, const char *appid,
320 category_x **category)
322 static const char query_raw[] =
323 "SELECT category FROM package_app_app_category WHERE app_id=%Q";
329 query = sqlite3_mprintf(query_raw, appid);
331 LOGE("out of memory");
332 return PMINFO_R_ERROR;
335 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
337 if (ret != SQLITE_OK) {
338 LOGE("prepare failed: %s", sqlite3_errmsg(db));
339 return PMINFO_R_ERROR;
342 while (sqlite3_step(stmt) == SQLITE_ROW) {
343 info = calloc(1, sizeof(category_x));
345 LOGE("out of memory");
346 sqlite3_finalize(stmt);
348 LISTHEAD(*category, info);
351 return PMINFO_R_ERROR;
353 _save_column_str(stmt, 0, &info->name);
354 LISTADD(*category, info);
358 LISTHEAD(*category, info);
362 sqlite3_finalize(stmt);
367 static void __parse_appcontrol(appcontrol_x **appcontrol, char *appcontrol_str)
374 if (appcontrol_str == NULL)
377 dup = strdup(appcontrol_str);
379 ac = calloc(1, sizeof(appcontrol_x));
381 _LOGE("out of memory");
384 token = strtok_r(dup, "|", &ptr);
385 if (token && strcmp(token, "NULL"))
386 ac->operation = strdup(token);
387 token = strtok_r(NULL, "|", &ptr);
388 if (token && strcmp(token, "NULL"))
389 ac->uri = strdup(token);
390 token = strtok_r(NULL, "|", &ptr);
391 if (token && strcmp(token, "NULL"))
392 ac->mime = strdup(token);
393 LISTADD(*appcontrol, ac);
394 } while ((token = strtok_r(NULL, ";", &ptr)));
397 LISTHEAD(*appcontrol, ac);
403 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
404 appcontrol_x **appcontrol)
406 static const char query_raw[] =
407 "SELECT app_control FROM package_app_app_control "
412 appcontrol_x *info = NULL;
415 query = sqlite3_mprintf(query_raw, appid);
417 LOGE("out of memory");
418 return PMINFO_R_ERROR;
421 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
423 if (ret != SQLITE_OK) {
424 LOGE("prepare failed: %s", sqlite3_errmsg(db));
425 return PMINFO_R_ERROR;
428 while (sqlite3_step(stmt) == SQLITE_ROW) {
430 _save_column_str(stmt, 0, (const char **)&str);
432 __parse_appcontrol(&info, str);
438 sqlite3_finalize(stmt);
443 static int _appinfo_get_data_control(sqlite3 *db, const char *appid,
444 datacontrol_x **datacontrol)
446 static const char query_raw[] =
447 "SELECT providerid, access, type "
448 "FROM package_app_data_control WHERE app_id=%Q";
455 query = sqlite3_mprintf(query_raw, appid);
457 LOGE("out of memory");
458 return PMINFO_R_ERROR;
461 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
463 if (ret != SQLITE_OK) {
464 LOGE("prepare failed: %s", sqlite3_errmsg(db));
465 return PMINFO_R_ERROR;
468 while (sqlite3_step(stmt) == SQLITE_ROW) {
469 info = calloc(1, sizeof(datacontrol_x));
471 LOGE("out of memory");
472 sqlite3_finalize(stmt);
474 LISTHEAD(*datacontrol, info);
477 return PMINFO_R_ERROR;
480 _save_column_str(stmt, idx++, &info->providerid);
481 _save_column_str(stmt, idx++, &info->access);
482 _save_column_str(stmt, idx++, &info->type);
483 LISTADD(*datacontrol, info);
487 LISTHEAD(*datacontrol, info);
491 sqlite3_finalize(stmt);
496 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
497 metadata_x **metadata)
499 static const char query_raw[] =
500 "SELECT md_key, md_value "
501 "FROM package_app_app_metadata WHERE app_id=%Q";
508 query = sqlite3_mprintf(query_raw, appid);
510 LOGE("out of memory");
511 return PMINFO_R_ERROR;
514 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
516 if (ret != SQLITE_OK) {
517 LOGE("prepare failed: %s", sqlite3_errmsg(db));
518 return PMINFO_R_ERROR;
521 while (sqlite3_step(stmt) == SQLITE_ROW) {
522 info = calloc(1, sizeof(metadata_x));
524 LOGE("out of memory");
525 sqlite3_finalize(stmt);
527 LISTHEAD(*metadata, info);
530 return PMINFO_R_ERROR;
533 _save_column_str(stmt, idx++, &info->key);
534 _save_column_str(stmt, idx++, &info->value);
535 LISTADD(*metadata, info);
539 LISTHEAD(*metadata, info);
543 sqlite3_finalize(stmt);
549 static int _appinfo_get_application(sqlite3 *db, const char *appid,
550 const char *locale, application_x **application)
552 static const char query_raw[] =
553 "SELECT app_id, app_component, app_exec, app_nodisplay, "
554 "app_type, app_onboot, app_multiple, app_autorestart, "
555 "app_taskmanage, app_enabled, app_hwacceleration, "
556 "app_screenreader, app_mainapp, app_recentimage, "
557 "app_launchcondition, app_indicatordisplay, app_portraitimg, "
558 "app_landscapeimg, app_guestmodevisibility, "
559 "app_permissiontype, app_preload, app_submode, "
560 "app_submode_mainid, app_launch_mode, app_ui_gadget, "
561 "app_support_disable, "
562 "component_type, package "
563 "FROM package_app_info WHERE app_id=%Q";
570 query = sqlite3_mprintf(query_raw, appid);
572 LOGE("out of memory");
573 return PMINFO_R_ERROR;
576 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
578 if (ret != SQLITE_OK) {
579 LOGE("prepare failed: %s", sqlite3_errmsg(db));
580 return PMINFO_R_ERROR;
583 ret = sqlite3_step(stmt);
584 if (ret == SQLITE_DONE) {
585 sqlite3_finalize(stmt);
586 return PMINFO_R_ENOENT;
587 } else if (ret != SQLITE_ROW) {
588 LOGE("step failed: %s", sqlite3_errmsg(db));
589 sqlite3_finalize(stmt);
590 return PMINFO_R_ERROR;
593 info = calloc(1, sizeof(application_x));
595 LOGE("out of memory");
596 sqlite3_finalize(stmt);
597 return PMINFO_R_ERROR;
600 _save_column_str(stmt, idx++, &info->appid);
601 _save_column_str(stmt, idx++, &info->component);
602 _save_column_str(stmt, idx++, &info->exec);
603 _save_column_str(stmt, idx++, &info->nodisplay);
604 _save_column_str(stmt, idx++, &info->type);
605 _save_column_str(stmt, idx++, &info->onboot);
606 _save_column_str(stmt, idx++, &info->multiple);
607 _save_column_str(stmt, idx++, &info->autorestart);
608 _save_column_str(stmt, idx++, &info->taskmanage);
609 _save_column_str(stmt, idx++, &info->enabled);
610 _save_column_str(stmt, idx++, &info->hwacceleration);
611 _save_column_str(stmt, idx++, &info->screenreader);
612 _save_column_str(stmt, idx++, &info->mainapp);
613 _save_column_str(stmt, idx++, &info->recentimage);
614 _save_column_str(stmt, idx++, &info->launchcondition);
615 _save_column_str(stmt, idx++, &info->indicatordisplay);
616 _save_column_str(stmt, idx++, &info->portraitimg);
617 _save_column_str(stmt, idx++, &info->landscapeimg);
618 _save_column_str(stmt, idx++, &info->guestmode_visibility);
619 _save_column_str(stmt, idx++, &info->permission_type);
620 _save_column_str(stmt, idx++, &info->preload);
621 _save_column_str(stmt, idx++, &info->submode);
622 _save_column_str(stmt, idx++, &info->submode_mainid);
623 _save_column_str(stmt, idx++, &info->launch_mode);
624 _save_column_str(stmt, idx++, &info->ui_gadget);
625 _save_column_str(stmt, idx++, &info->support_disable);
626 _save_column_str(stmt, idx++, &info->component_type);
627 _save_column_str(stmt, idx++, &info->package);
629 if (_appinfo_get_label(db, info->appid, locale, &info->label)) {
630 pkgmgrinfo_basic_free_application(info);
631 sqlite3_finalize(stmt);
632 return PMINFO_R_ERROR;
635 if (_appinfo_get_icon(db, info->appid, locale, &info->icon)) {
636 pkgmgrinfo_basic_free_application(info);
637 sqlite3_finalize(stmt);
638 return PMINFO_R_ERROR;
641 if (_appinfo_get_category(db, info->appid, &info->category)) {
642 pkgmgrinfo_basic_free_application(info);
643 sqlite3_finalize(stmt);
644 return PMINFO_R_ERROR;
647 if (_appinfo_get_app_control(db, info->appid, &info->appcontrol)) {
648 pkgmgrinfo_basic_free_application(info);
649 sqlite3_finalize(stmt);
650 return PMINFO_R_ERROR;
653 if (_appinfo_get_data_control(db, info->appid, &info->datacontrol)) {
654 pkgmgrinfo_basic_free_application(info);
655 sqlite3_finalize(stmt);
656 return PMINFO_R_ERROR;
659 if (_appinfo_get_metadata(db, info->appid, &info->metadata)) {
660 pkgmgrinfo_basic_free_application(info);
661 sqlite3_finalize(stmt);
662 return PMINFO_R_ERROR;
667 sqlite3_finalize(stmt);
672 static int _appinfo_get_appinfo(const char *appid, uid_t uid,
673 pkgmgr_appinfo_x **appinfo)
679 pkgmgr_appinfo_x *info;
681 dbpath = getUserPkgParserDBPathUID(uid);
683 return PMINFO_R_ERROR;
685 locale = _get_system_locale();
687 return PMINFO_R_ERROR;
689 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
690 if (ret != SQLITE_OK) {
691 _LOGE("failed to open db: %d", ret);
693 return PMINFO_R_ERROR;
696 info = calloc(1, sizeof(pkgmgr_appinfo_x));
698 _LOGE("out of memory");
700 sqlite3_close_v2(db);
701 return PMINFO_R_ERROR;
704 ret = _appinfo_get_application(db, appid, locale, &info->app_info);
705 if (ret != PMINFO_R_OK) {
708 sqlite3_close_v2(db);
712 info->locale = locale;
713 info->package = strdup(info->app_info->package);
717 sqlite3_close_v2(db);
722 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
723 pkgmgrinfo_appinfo_h *handle)
727 if (appid == NULL || handle == NULL) {
728 LOGE("invalid parameter");
729 return PMINFO_R_EINVAL;
732 ret = _appinfo_get_appinfo(appid, uid, (pkgmgr_appinfo_x **)handle);
733 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
734 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
735 (pkgmgr_appinfo_x **)handle);
737 if (ret != PMINFO_R_OK)
738 _LOGE("failed to get appinfo of %s for user %d", appid, uid);
743 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
745 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
748 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
749 pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb,
753 pkgmgr_appinfo_x *info;
759 ret = _appinfo_get_filtered_list(filter, uid, &list);
760 if (ret != PMINFO_R_OK)
761 return PMINFO_R_ERROR;
763 for (tmp = list; tmp; tmp = tmp->next) {
764 appid = (char *)tmp->data;
766 ret = _appinfo_get_appinfo(appid, uid, &info);
767 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
768 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
770 if (ret != PMINFO_R_OK) {
774 if (app_list_cb(info, user_data) < 0)
776 pkgmgrinfo_appinfo_destroy_appinfo(info);
786 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
787 pkgmgrinfo_app_component component,
788 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
791 pkgmgrinfo_appinfo_filter_h filter;
793 const char *comp_str = NULL;
795 if (handle == NULL || app_func == NULL) {
796 LOGE("invalied parameter");
797 return PMINFO_R_EINVAL;
800 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
801 LOGE("invalid parameter");
802 return PMINFO_R_EINVAL;
805 if (pkgmgrinfo_appinfo_filter_create(&filter))
806 return PMINFO_R_ERROR;
808 if (pkgmgrinfo_appinfo_filter_add_string(filter,
809 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
810 pkgmgrinfo_appinfo_filter_destroy(filter);
811 return PMINFO_R_ERROR;
817 comp_str = PMINFO_APPINFO_UI_APP;
820 comp_str = PMINFO_APPINFO_SVC_APP;
827 if (pkgmgrinfo_appinfo_filter_add_string(filter,
828 PMINFO_APPINFO_PROP_APP_COMPONENT,
830 pkgmgrinfo_appinfo_filter_destroy(filter);
831 return PMINFO_R_ERROR;
835 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, app_func,
838 pkgmgrinfo_appinfo_filter_destroy(filter);
843 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
844 pkgmgrinfo_app_list_cb app_func, void *user_data)
846 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
849 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
851 if (app_func == NULL) {
852 LOGE("invalid parameter");
853 return PMINFO_R_EINVAL;
856 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
860 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
862 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
865 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
867 if (app_func == NULL) {
868 LOGE("invalid parameter");
869 return PMINFO_R_EINVAL;
872 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
876 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
878 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
881 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
883 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
885 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
886 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
888 if (info->app_info == NULL || info->app_info->appid == NULL)
889 return PMINFO_R_ERROR;
890 *appid = (char *)info->app_info->appid;
895 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
897 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
899 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
900 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
902 if (info->package == NULL)
903 return PMINFO_R_ERROR;
905 *pkg_name = (char *)info->package;
910 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
912 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
914 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
915 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
917 if (info->package == NULL)
918 return PMINFO_R_ERROR;
920 *pkgid = (char *)info->package;
925 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
927 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
929 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
930 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
932 if (info->app_info == NULL || info->app_info->exec == NULL)
933 return PMINFO_R_ERROR;
934 *exec = (char *)info->app_info->exec;
940 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
945 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
947 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
948 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
950 locale = info->locale;
951 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
953 start = info->app_info->icon;
954 for (ptr = start; ptr != NULL; ptr = ptr->next) {
955 if (ptr->lang == NULL)
958 if (strcmp(ptr->lang, locale) == 0) {
959 *icon = (char *)ptr->text;
960 if (strcasecmp(*icon, "(null)") == 0) {
961 locale = DEFAULT_LOCALE;
966 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
967 *icon = (char *)ptr->text;
972 return PMINFO_R_ERROR;
976 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
981 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
983 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
984 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
986 locale = info->locale;
987 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
989 start = info->app_info->label;
990 for (ptr = start; ptr != NULL; ptr = ptr->next) {
991 if (ptr->lang == NULL)
994 if (strcmp(ptr->lang, locale) == 0) {
995 *label = (char *)ptr->text;
996 if (strcasecmp(*label, "(null)") == 0) {
997 locale = DEFAULT_LOCALE;
1002 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
1003 *label = (char *)ptr->text;
1008 return PMINFO_R_ERROR;
1011 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1013 char *result = NULL;
1015 sqlite3_stmt *stmt = NULL;
1018 const char *manifest_db;
1020 manifest_db = getUserPkgParserDBPathUID(uid);
1021 if (manifest_db == NULL) {
1022 _LOGE("Failed to get manifest db path");
1026 if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
1027 _LOGE("DB open fail\n");
1031 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1032 if (query == NULL) {
1033 _LOGE("Out of memory");
1037 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1038 _LOGE("prepare_v2 fail\n");
1042 if (sqlite3_step(stmt) == SQLITE_ROW) {
1043 val = (char *)sqlite3_column_text(stmt, 0);
1045 result = strdup(val);
1049 sqlite3_finalize(stmt);
1050 sqlite3_free(query);
1056 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1060 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1062 val = _get_localed_label(appid, locale, uid);
1064 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1067 return PMINFO_R_ERROR;
1074 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1076 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
1079 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1081 if ( strcasecmp(comp, "uiapp") == 0)
1082 return PMINFO_UI_APP;
1083 else if ( strcasecmp(comp, "svcapp") == 0)
1084 return PMINFO_SVC_APP;
1089 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1091 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1094 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1095 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1097 if (info->app_info == NULL)
1098 return PMINFO_R_ERROR;
1100 comp = __appcomponent_convert(info->app_info->component);
1102 return PMINFO_R_ERROR;
1109 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1111 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1113 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1114 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1116 if (info->app_info == NULL || info->app_info->type == NULL)
1117 return PMINFO_R_ERROR;
1118 *app_type = (char *)info->app_info->type;
1123 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
1124 int *operation_count, char ***operation)
1126 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1127 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1128 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1129 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1130 *operation_count = data->operation_count;
1131 *operation = data->operation;
1135 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
1136 int *uri_count, char ***uri)
1138 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1139 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1140 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1141 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1142 *uri_count = data->uri_count;
1147 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
1148 int *mime_count, char ***mime)
1150 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1151 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1152 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1153 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1154 *mime_count = data->mime_count;
1159 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1160 int *subapp_count, char ***subapp)
1162 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1163 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1164 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1165 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1166 *subapp_count = data->subapp_count;
1167 *subapp = data->subapp;
1171 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1175 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1177 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1178 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1180 for (ptr = info->app_info->icon; ptr != NULL; ptr = ptr->next) {
1181 if (ptr->section == NULL)
1184 val = (char *)ptr->section;
1185 if (val && strcmp(val, "setting") == 0) {
1186 *icon = (char *)ptr->text;
1191 return PMINFO_R_ERROR;
1195 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1199 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1201 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1202 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1204 for (ptr = info->app_info->icon; ptr != NULL; ptr = ptr->next) {
1205 if (ptr->section == NULL)
1208 val = (char *)ptr->section;
1209 if (val && strcmp(val, "notification") == 0){
1210 *icon = (char *)ptr->text;
1215 return PMINFO_R_ERROR;
1218 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1221 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1223 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1224 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1226 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1227 return PMINFO_R_ERROR;
1229 val = (char *)info->app_info->recentimage;
1230 if (strcasecmp(val, "capture") == 0)
1231 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1232 else if (strcasecmp(val, "icon") == 0)
1233 *type = PMINFO_RECENTIMAGE_USE_ICON;
1235 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1240 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1244 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1246 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1247 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1249 for (ptr = info->app_info->image; ptr != NULL; ptr = ptr->next) {
1250 if (ptr->section == NULL)
1253 val = (char *)ptr->section;
1254 if (val && strcmp(val, "preview") == 0) {
1255 *preview_img = (char *)ptr->text;
1260 return PMINFO_R_ERROR;
1263 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1266 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1268 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1269 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1271 val = info->app_info->permission_type;
1273 return PMINFO_R_ERROR;
1275 if (strcmp(val, "signature") == 0)
1276 *permission = PMINFO_PERMISSION_SIGNATURE;
1277 else if (strcmp(val, "privilege") == 0)
1278 *permission = PMINFO_PERMISSION_PRIVILEGE;
1280 *permission = PMINFO_PERMISSION_NORMAL;
1285 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1287 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1289 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1290 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1292 if (info->app_info == NULL || info->app_info->component_type == NULL)
1293 return PMINFO_R_ERROR;
1295 *component_type = (char *)info->app_info->component_type;
1300 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1303 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1305 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1306 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1308 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1309 return PMINFO_R_ERROR;
1311 val = (char *)info->app_info->hwacceleration;
1312 if (strcasecmp(val, "not-use-GL") == 0)
1313 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
1314 else if (strcasecmp(val, "use-GL") == 0)
1315 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
1317 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
1322 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1325 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1327 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1328 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1330 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1331 return PMINFO_R_ERROR;
1333 val = (char *)info->app_info->screenreader;
1334 if (strcasecmp(val, "screenreader-off") == 0)
1335 *screenreader = PMINFO_SCREENREADER_OFF;
1336 else if (strcasecmp(val, "screenreader-on") == 0)
1337 *screenreader = PMINFO_SCREENREADER_ON;
1339 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1344 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1346 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1348 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1349 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1350 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1352 if (info->app_info == NULL || info->app_info->portraitimg ||
1353 info->app_info->landscapeimg == NULL)
1354 return PMINFO_R_ERROR;
1356 *portrait_img = (char *)info->app_info->portraitimg;
1357 *landscape_img = (char *)info->app_info->landscapeimg;
1362 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
1364 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1366 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1367 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1369 if (info->app_info == NULL || info->app_info->submode_mainid == NULL)
1370 return PMINFO_R_ERROR;
1372 *submode_mainid = (char *)info->app_info->submode_mainid;
1377 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
1379 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1381 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1382 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1384 if (info->app_info->launch_mode == NULL)
1385 return PMINFO_R_ERROR;
1387 *mode = (char *)(info->app_info->launch_mode);
1392 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
1394 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1395 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1396 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1397 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1399 int ret = PMINFO_R_OK;
1401 sqlite3_stmt *stmt = NULL;
1404 ret = __open_manifest_db(uid, true);
1405 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1407 /*Start constructing query*/
1408 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
1411 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1412 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1415 ret = sqlite3_step(stmt);
1416 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1418 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1419 *access = strdup((char *)sqlite3_column_text(stmt, 2));
1424 sqlite3_free(query);
1425 sqlite3_finalize(stmt);
1426 __close_manifest_db();
1430 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
1432 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
1435 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
1437 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1438 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1440 int ret = PMINFO_R_OK;
1442 sqlite3_stmt *stmt = NULL;
1445 ret = __open_manifest_db(uid, true);
1446 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1448 /*Start constructing query*/
1449 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
1452 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1453 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1456 ret = sqlite3_step(stmt);
1457 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1459 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1464 sqlite3_free(query);
1465 sqlite3_finalize(stmt);
1466 __close_manifest_db();
1470 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1472 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
1475 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
1476 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
1478 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1479 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1481 permission_x *ptr = NULL;
1482 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1484 if (info->app_info == NULL)
1485 return PMINFO_R_ERROR;
1487 for (ptr = info->app_info->permission; ptr; ptr = ptr->next) {
1489 ret = permission_func(ptr->value, user_data);
1497 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
1498 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
1500 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1501 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1503 category_x *ptr = NULL;
1504 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1506 if (info->app_info == NULL)
1507 return PMINFO_R_ERROR;
1509 for (ptr = info->app_info->category; ptr; ptr = ptr->next) {
1511 ret = category_func(ptr->name, user_data);
1519 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
1520 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
1522 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1523 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1525 metadata_x *ptr = NULL;
1526 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1528 if (info->app_info == NULL)
1529 return PMINFO_R_ERROR;
1531 for (ptr = info->app_info->metadata; ptr; ptr = ptr->next) {
1533 ret = metadata_func(ptr->key, ptr->value, user_data);
1541 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
1542 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1544 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1545 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1547 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1548 appcontrol_x *appcontrol;
1550 if (info->uiapp_info == NULL)
1551 return PMINFO_R_ERROR;
1553 for (appcontrol = info->app_info->appcontrol; appcontrol; appcontrol = appcontrol->next) {
1554 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1562 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
1564 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1565 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1566 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1568 if (info->app_info == NULL || info->app_info->nodisplay == NULL)
1569 return PMINFO_R_ERROR;
1571 *nodisplay = _get_bool_value(info->app_info->nodisplay);
1576 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
1578 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1579 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1580 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1582 if (info->app_info == NULL || info->app_info->multiple == NULL)
1583 return PMINFO_R_ERROR;
1585 *multiple = _get_bool_value(info->app_info->multiple);
1590 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
1592 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1593 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1594 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1596 if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
1597 return PMINFO_R_ERROR;
1599 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
1604 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
1606 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1607 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1608 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1610 if (info->app_info == NULL || info->app_info->taskmanage == NULL)
1611 return PMINFO_R_ERROR;
1613 *taskmanage = _get_bool_value(info->app_info->taskmanage);
1618 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
1620 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1621 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1622 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1624 if (info->app_info == NULL || info->app_info->enabled == NULL)
1625 return PMINFO_R_ERROR;
1627 *enabled = _get_bool_value(info->app_info->enabled);
1632 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
1634 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1635 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1636 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1638 if (info->app_info == NULL || info->app_info->onboot == NULL)
1639 return PMINFO_R_ERROR;
1641 *onboot = _get_bool_value(info->app_info->onboot);
1646 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
1648 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1649 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1650 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1652 if (info->app_info == NULL || info->app_info->autorestart == NULL)
1653 return PMINFO_R_ERROR;
1655 *autorestart = _get_bool_value(info->app_info->autorestart);
1660 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
1662 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1663 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1664 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1666 if (info->app_info == NULL || info->app_info->mainapp == NULL)
1667 return PMINFO_R_ERROR;
1669 *mainapp = _get_bool_value(info->app_info->mainapp);
1674 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
1676 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1677 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1678 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1680 if (info->app_info == NULL || info->app_info->preload == NULL)
1681 return PMINFO_R_ERROR;
1683 *preload = _get_bool_value(info->app_info->preload);
1688 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
1690 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1691 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1692 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1694 if (info->app_info == NULL || info->app_info->submode == NULL)
1695 return PMINFO_R_ERROR;
1697 *submode = _get_bool_value(info->app_info->submode);
1702 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
1704 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1705 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
1706 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
1708 category_x *ptr = NULL;
1709 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1711 if (info->app_info == NULL)
1712 return PMINFO_R_ERROR;
1715 for (ptr = info->app_info->category; ptr; ptr = ptr->next) {
1717 if (strcasecmp(ptr->name, category) == 0) {
1727 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
1730 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1732 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
1733 _LOGE("invalid parameter");
1734 return PMINFO_R_EINVAL;
1737 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
1742 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
1743 bool *support_disable)
1745 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1747 if (info == NULL || info->app_info == NULL || support_disable == NULL) {
1748 _LOGE("invalid parameter");
1749 return PMINFO_R_EINVAL;
1752 *support_disable = _get_bool_value(info->app_info->support_disable);
1757 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
1759 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1760 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1761 __cleanup_appinfo(info);
1765 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
1767 return (pkgmgrinfo_pkginfo_filter_create(handle));
1770 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
1772 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1775 static gint __compare_func(gconstpointer data1, gconstpointer data2)
1777 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
1778 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
1779 if (node1->prop == node2->prop)
1781 else if (node1->prop > node2->prop)
1787 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
1788 const char *property, const int value)
1790 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1791 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1792 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1794 GSList *link = NULL;
1796 prop = _pminfo_appinfo_convert_to_prop_int(property);
1797 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
1798 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
1799 _LOGE("Invalid Integer Property\n");
1800 return PMINFO_R_EINVAL;
1802 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1803 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1805 _LOGE("Out of Memory!!!\n");
1806 return PMINFO_R_ERROR;
1808 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1809 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1811 _LOGE("Out of Memory\n");
1814 return PMINFO_R_ERROR;
1818 /*If API is called multiple times for same property, we should override the previous values.
1819 Last value set will be used for filtering.*/
1820 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1822 filter->list = g_slist_delete_link(filter->list, link);
1823 filter->list = g_slist_append(filter->list, (gpointer)node);
1828 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
1829 const char *property, const bool value)
1831 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1832 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1834 GSList *link = NULL;
1836 prop = _pminfo_appinfo_convert_to_prop_bool(property);
1837 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
1838 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
1839 _LOGE("Invalid Boolean Property\n");
1840 return PMINFO_R_EINVAL;
1842 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1843 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1845 _LOGE("Out of Memory!!!\n");
1846 return PMINFO_R_ERROR;
1849 val = strndup("('true','True')", 15);
1851 val = strndup("('false','False')", 17);
1853 _LOGE("Out of Memory\n");
1856 return PMINFO_R_ERROR;
1860 /*If API is called multiple times for same property, we should override the previous values.
1861 Last value set will be used for filtering.*/
1862 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1864 filter->list = g_slist_delete_link(filter->list, link);
1865 filter->list = g_slist_append(filter->list, (gpointer)node);
1870 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
1871 const char *property, const char *value)
1873 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1874 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1875 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1877 pkgmgrinfo_node_x *ptr = NULL;
1878 char prev[PKG_STRING_LEN_MAX] = {'\0'};
1879 char temp[PKG_STRING_LEN_MAX] = {'\0'};
1880 GSList *link = NULL;
1882 prop = _pminfo_appinfo_convert_to_prop_str(property);
1883 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
1884 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
1885 _LOGE("Invalid String Property\n");
1886 return PMINFO_R_EINVAL;
1888 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1889 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1891 _LOGE("Out of Memory!!!\n");
1892 return PMINFO_R_ERROR;
1896 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
1897 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
1898 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
1900 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
1902 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1904 filter->list = g_slist_delete_link(filter->list, link);
1905 filter->list = g_slist_append(filter->list, (gpointer)node);
1907 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
1908 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
1909 case E_PMINFO_APPINFO_PROP_APP_URI:
1910 case E_PMINFO_APPINFO_PROP_APP_MIME:
1911 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
1913 _LOGE("Out of Memory\n");
1916 return PMINFO_R_ERROR;
1918 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1920 ptr = (pkgmgrinfo_node_x *)link->data;
1921 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
1922 _LOGE("Previous value is %s\n", prev);
1923 filter->list = g_slist_delete_link(filter->list, link);
1924 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
1925 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1926 _LOGE("New value is %s\n", val);
1928 filter->list = g_slist_append(filter->list, (gpointer)node);
1929 memset(temp, '\0', PKG_STRING_LEN_MAX);
1931 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
1932 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1933 _LOGE("First value is %s\n", val);
1935 filter->list = g_slist_append(filter->list, (gpointer)node);
1936 memset(temp, '\0', PKG_STRING_LEN_MAX);
1940 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
1941 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1943 filter->list = g_slist_delete_link(filter->list, link);
1944 filter->list = g_slist_append(filter->list, (gpointer)node);
1950 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
1955 if (handle == NULL || count == NULL) {
1956 _LOGE("invalid parameter");
1957 return PMINFO_R_EINVAL;
1960 ret = _appinfo_get_filtered_list(handle, uid, &list);
1961 if (ret != PMINFO_R_OK)
1962 return PMINFO_R_ERROR;
1964 *count = g_list_length(list);
1966 g_list_free_full(list, free);
1971 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
1973 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
1976 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
1977 pkgmgrinfo_appinfo_filter_h handle,
1978 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
1980 if (handle == NULL || app_cb == NULL) {
1981 LOGE("invalid parameter");
1982 return PMINFO_R_EINVAL;
1985 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
1989 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
1990 pkgmgrinfo_app_list_cb app_cb, void * user_data)
1992 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
1995 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
1997 return (pkgmgrinfo_pkginfo_filter_create(handle));
2000 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
2002 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2005 API int pkgmgrinfo_appinfo_metadata_filter_add(
2006 pkgmgrinfo_appinfo_metadata_filter_h handle,
2007 const char *key, const char *value)
2011 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2012 PMINFO_APPINFO_PROP_APP_METADATA_KEY, key);
2013 if (ret != PMINFO_R_OK)
2016 /* value can be NULL.
2017 * In that case all apps with specified key should be displayed
2020 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2021 PMINFO_APPINFO_PROP_APP_METADATA_VALUE, value);
2022 if (ret != PMINFO_R_OK)
2029 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2030 pkgmgrinfo_appinfo_metadata_filter_h handle,
2031 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2033 if (handle == NULL || app_cb == NULL) {
2034 LOGE("invalid parameter");
2035 return PMINFO_R_EINVAL;
2038 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2042 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
2043 pkgmgrinfo_appinfo_metadata_filter_h handle,
2044 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2046 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
2047 user_data, GLOBAL_USER);
2050 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2053 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2055 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2056 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2058 val = info->uiapp_info->guestmode_visibility;
2059 *status = _get_bool_value(val);