13 #include "pkgmgr-info.h"
14 #include "pkgmgrinfo_debug.h"
15 #include "pkgmgrinfo_private.h"
16 #include "pkgmgr_parser.h"
17 #include "manager/pkginfo_manager.h"
19 static bool _get_bool_value(const char *str)
21 if (str && !strcmp(str, "true"))
27 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
29 pkgmgr_appinfo_x *info = data;
33 free((void *)info->package);
35 free((void *)info->locale);
37 pkgmgrinfo_basic_free_application(info->app_info);
43 static void __free_applications(gpointer data)
45 pkgmgrinfo_basic_free_application((application_x *)data);
48 static gint __disable_chk_func(gconstpointer data1, gconstpointer data2)
50 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1;
51 pkgmgrinfo_appinfo_disable_type value = GPOINTER_TO_INT(data2);
53 if (value == E_APPINFO_DISABLE_TYPE_PKG)
54 return (node->prop == E_PMINFO_APPINFO_PROP_PKG_DISABLE)
57 return (node->prop == E_PMINFO_APPINFO_PROP_APP_DISABLE)
61 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter,
62 pkgmgrinfo_appinfo_disable_type type)
69 link = g_slist_find_custom(filter->list, GINT_TO_POINTER(type), __disable_chk_func);
76 static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
77 pkgmgrinfo_appinfo_filter_h filter, pkgmgrinfo_appinfo_h *handle)
79 int ret = PMINFO_R_OK;
81 pkgmgr_appinfo_x *info;
83 if (appid == NULL || filter == NULL || handle == NULL) {
84 LOGE("invalid parameter");
85 return PMINFO_R_EINVAL;
88 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
91 return PMINFO_R_ERROR;
93 // TODO: need to use pkginfo-client APIs
94 ret = _appinfo_get_applications(uid, uid, filter,
95 PMINFO_APPINFO_GET_ALL, list);
96 if (ret != PMINFO_R_OK) {
97 g_hash_table_destroy(list);
101 if (!g_hash_table_size(list)) {
102 _LOGD("appinfo for [%s] is not existed for user [%d]",
104 g_hash_table_destroy(list);
105 return PMINFO_R_ENOENT;
108 info = calloc(1, sizeof(pkgmgr_appinfo_x));
110 _LOGE("out of memory");
111 g_hash_table_destroy(list);
112 return PMINFO_R_ERROR;
115 info->app_info = (application_x *)g_hash_table_lookup(list, appid);
116 if (!info->app_info || !info->app_info->package) {
117 _LOGD("appinfo for [%s] is not existed for user [%d]",
119 g_hash_table_destroy(list);
121 return PMINFO_R_ENOENT;
123 info->locale = strdup(info->app_info->locale);
124 info->package = strdup(info->app_info->package);
125 if (!info->package || !info->locale) {
126 _LOGE("out of memory");
127 g_hash_table_destroy(list);
129 return PMINFO_R_ERROR;
132 /* just free list only */
133 g_hash_table_steal(list, (gconstpointer)appid);
134 g_hash_table_destroy(list);
141 API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid,
142 pkgmgrinfo_appinfo_h *handle)
145 pkgmgrinfo_appinfo_filter_h filter;
147 if (appid == NULL || handle == NULL) {
148 LOGE("invalid parameter");
149 return PMINFO_R_EINVAL;
152 ret = pkgmgrinfo_appinfo_filter_create(&filter);
153 if (ret != PMINFO_R_OK)
156 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
157 PMINFO_APPINFO_PROP_APP_ID, appid);
158 if (ret != PMINFO_R_OK) {
159 pkgmgrinfo_appinfo_filter_destroy(filter);
160 return PMINFO_R_ERROR;
163 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
164 PMINFO_APPINFO_PROP_APP_DISABLE, true);
165 if (ret != PMINFO_R_OK) {
166 pkgmgrinfo_appinfo_filter_destroy(filter);
167 return PMINFO_R_ERROR;
170 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
171 pkgmgrinfo_appinfo_filter_destroy(filter);
176 API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
178 return pkgmgrinfo_appinfo_get_usr_disabled_appinfo(appid, _getuid(), handle);
181 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
182 pkgmgrinfo_appinfo_h *handle)
185 pkgmgrinfo_appinfo_filter_h filter;
187 if (appid == NULL || handle == NULL) {
188 LOGE("invalid parameter");
189 return PMINFO_R_EINVAL;
192 ret = pkgmgrinfo_appinfo_filter_create(&filter);
193 if (ret != PMINFO_R_OK)
196 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
197 PMINFO_APPINFO_PROP_APP_ID, appid);
198 if (ret != PMINFO_R_OK) {
199 pkgmgrinfo_appinfo_filter_destroy(filter);
200 return PMINFO_R_ERROR;
203 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
204 PMINFO_APPINFO_PROP_APP_DISABLE, false);
205 if (ret != PMINFO_R_OK) {
206 pkgmgrinfo_appinfo_filter_destroy(filter);
207 return PMINFO_R_ERROR;
210 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
211 PMINFO_APPINFO_PROP_PKG_DISABLE, false);
212 if (ret != PMINFO_R_OK) {
213 pkgmgrinfo_appinfo_filter_destroy(filter);
214 return PMINFO_R_ERROR;
217 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
218 pkgmgrinfo_appinfo_filter_destroy(filter);
222 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
224 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, _getuid(), handle);
227 API int pkgmgrinfo_appinfo_get_usr_all_appinfo(const char *appid, uid_t uid,
228 pkgmgrinfo_appinfo_h *handle)
231 pkgmgrinfo_appinfo_filter_h filter;
233 if (appid == NULL || handle == NULL) {
234 LOGE("invalid parameter");
235 return PMINFO_R_EINVAL;
238 ret = pkgmgrinfo_appinfo_filter_create(&filter);
239 if (ret != PMINFO_R_OK)
242 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
243 PMINFO_APPINFO_PROP_APP_ID, appid);
244 if (ret != PMINFO_R_OK) {
245 pkgmgrinfo_appinfo_filter_destroy(filter);
246 return PMINFO_R_ERROR;
249 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
250 PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false);
251 if (ret != PMINFO_R_OK) {
252 pkgmgrinfo_appinfo_filter_destroy(filter);
253 return PMINFO_R_ERROR;
256 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
257 pkgmgrinfo_appinfo_filter_destroy(filter);
262 API int pkgmgrinfo_appinfo_get_all_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
264 return pkgmgrinfo_appinfo_get_usr_all_appinfo(appid, _getuid(), handle);
267 static gpointer __copy_str(gconstpointer src, gpointer data)
269 const char *tmp = (const char *)src;
272 buffer = strdup(tmp);
273 if (buffer == NULL) {
274 LOGE("memory alloc failed");
282 static gpointer __copy_label(gconstpointer src, gpointer data)
284 label_x *tmp = (label_x *)src;
287 label = calloc(1, sizeof(label_x));
289 LOGE("memory alloc failed");
295 label->name = strdup(tmp->name);
297 label->text = strdup(tmp->text);
299 label->lang = strdup(tmp->lang);
304 static gpointer __copy_icon(gconstpointer src, gpointer data)
306 icon_x *tmp = (icon_x *)src;
309 icon = calloc(1, sizeof(icon_x));
311 LOGE("memory alloc failed");
317 icon->text = strdup(tmp->text);
319 icon->lang = strdup(tmp->lang);
321 icon->section = strdup(tmp->section);
323 icon->size = strdup(tmp->size);
325 icon->resolution = strdup(tmp->resolution);
330 static gpointer __copy_metadata(gconstpointer src, gpointer data)
332 metadata_x *tmp = (metadata_x *)src;
333 metadata_x *metadata;
335 metadata = calloc(1, sizeof(metadata_x));
336 if (metadata == NULL) {
337 LOGE("memory alloc failed");
343 metadata->key = strdup(tmp->key);
345 metadata->value = strdup(tmp->value);
350 static gpointer __copy_datacontrol(gconstpointer src, gpointer data)
352 datacontrol_x *tmp = (datacontrol_x *)src;
353 datacontrol_x *datacontrol;
355 datacontrol = calloc(1, sizeof(datacontrol_x));
356 if (datacontrol == NULL) {
357 LOGE("memory alloc failed");
363 datacontrol->providerid = strdup(tmp->providerid);
365 datacontrol->access = strdup(tmp->access);
367 datacontrol->type = strdup(tmp->type);
369 datacontrol->trusted = strdup(tmp->trusted);
374 static gpointer __copy_appcontrol(gconstpointer src, gpointer data)
376 appcontrol_x *tmp = (appcontrol_x *)src;
377 appcontrol_x *appcontrol;
379 appcontrol = calloc(1, sizeof(appcontrol_x));
380 if (appcontrol == NULL) {
381 LOGE("memory alloc failed");
387 appcontrol->operation = strdup(tmp->operation);
389 appcontrol->uri = strdup(tmp->uri);
391 appcontrol->mime = strdup(tmp->mime);
396 static gpointer __copy_splashscreens(gconstpointer src, gpointer data)
398 splashscreen_x *tmp = (splashscreen_x *)src;
399 splashscreen_x *splashscreen;
401 splashscreen = (splashscreen_x *)calloc(1, sizeof(splashscreen_x));
402 if (splashscreen == NULL) {
403 LOGE("memory alloc failed");
409 splashscreen->src = strdup(tmp->src);
411 splashscreen->type = strdup(tmp->type);
412 if (tmp->orientation)
413 splashscreen->orientation = strdup(tmp->orientation);
414 if (tmp->indicatordisplay)
415 splashscreen->indicatordisplay = strdup(tmp->indicatordisplay);
417 splashscreen->operation = strdup(tmp->operation);
418 if (tmp->color_depth)
419 splashscreen->color_depth = strdup(tmp->color_depth);
424 static int _appinfo_copy_appinfo(application_x **application, application_x *data)
426 application_x *app_info;
429 app_info = calloc(1, sizeof(application_x));
430 if (app_info == NULL) {
431 LOGE("memory alloc failed");
432 return PMINFO_R_ERROR;
435 if (data->appid != NULL)
436 app_info->appid = strdup(data->appid);
437 if (data->exec != NULL)
438 app_info->exec = strdup(data->exec);
439 if (data->nodisplay != NULL)
440 app_info->nodisplay = strdup(data->nodisplay);
441 if (data->multiple != NULL)
442 app_info->multiple = strdup(data->multiple);
443 if (data->taskmanage != NULL)
444 app_info->taskmanage = strdup(data->taskmanage);
445 if (data->type != NULL)
446 app_info->type = strdup(data->type);
447 if (data->categories != NULL)
448 app_info->categories = strdup(data->categories);
449 if (data->hwacceleration != NULL)
450 app_info->hwacceleration = strdup(data->hwacceleration);
451 if (data->screenreader != NULL)
452 app_info->screenreader = strdup(data->screenreader);
453 if (data->mainapp != NULL)
454 app_info->mainapp = strdup(data->mainapp);
455 if (data->package != NULL)
456 app_info->package = strdup(data->package);
457 if (data->recentimage != NULL)
458 app_info->recentimage = strdup(data->recentimage);
459 if (data->launchcondition != NULL)
460 app_info->launchcondition = strdup(data->launchcondition);
461 if (data->indicatordisplay != NULL)
462 app_info->indicatordisplay = strdup(data->indicatordisplay);
463 if (data->portraitimg != NULL)
464 app_info->portraitimg = strdup(data->portraitimg);
465 if (data->landscapeimg != NULL)
466 app_info->landscapeimg = strdup(data->landscapeimg);
467 if (data->guestmode_visibility != NULL)
468 app_info->guestmode_visibility = strdup(data->guestmode_visibility);
469 if (data->component != NULL)
470 app_info->component = strdup(data->component);
471 if (data->permission_type != NULL)
472 app_info->permission_type = strdup(data->permission_type);
473 if (data->component_type != NULL)
474 app_info->component_type = strdup(data->component_type);
475 if (data->preload != NULL)
476 app_info->preload = strdup(data->preload);
477 if (data->submode != NULL)
478 app_info->submode = strdup(data->submode);
479 if (data->submode_mainid != NULL)
480 app_info->submode_mainid = strdup(data->submode_mainid);
481 if (data->process_pool != NULL)
482 app_info->process_pool = strdup(data->process_pool);
483 if (data->installed_storage != NULL)
484 app_info->installed_storage = strdup(data->installed_storage);
485 if (data->autorestart != NULL)
486 app_info->autorestart = strdup(data->autorestart);
487 if (data->onboot != NULL)
488 app_info->onboot = strdup(data->onboot);
489 if (data->support_disable != NULL)
490 app_info->support_disable = strdup(data->support_disable);
491 if (data->ui_gadget != NULL)
492 app_info->ui_gadget = strdup(data->ui_gadget);
493 if (data->launch_mode != NULL)
494 app_info->launch_mode = strdup(data->launch_mode);
495 if (data->package_type != NULL)
496 app_info->package_type = strdup(data->package_type);
497 if (data->effective_appid != NULL)
498 app_info->effective_appid = strdup(data->effective_appid);
499 if (data->splash_screen_display != NULL)
500 app_info->splash_screen_display = strdup(data->splash_screen_display);
504 app_info->label = g_list_copy_deep(data->label, __copy_label, &ret);
506 LOGE("memory alloc failed");
507 pkgmgrinfo_basic_free_application(app_info);
508 return PMINFO_R_ERROR;
512 app_info->icon = g_list_copy_deep(data->icon, __copy_icon, &ret);
514 LOGE("memory alloc failed");
515 pkgmgrinfo_basic_free_application(app_info);
516 return PMINFO_R_ERROR;
520 app_info->category = g_list_copy_deep(data->category, __copy_str, &ret);
522 LOGE("memory alloc failed");
523 pkgmgrinfo_basic_free_application(app_info);
524 return PMINFO_R_ERROR;
528 app_info->metadata = g_list_copy_deep(data->metadata, __copy_metadata, &ret);
530 LOGE("memory alloc failed");
531 pkgmgrinfo_basic_free_application(app_info);
532 return PMINFO_R_ERROR;
536 app_info->datacontrol = g_list_copy_deep(data->datacontrol, __copy_datacontrol, &ret);
538 LOGE("memory alloc failed");
539 pkgmgrinfo_basic_free_application(app_info);
540 return PMINFO_R_ERROR;
544 app_info->appcontrol = g_list_copy_deep(data->appcontrol, __copy_appcontrol, &ret);
546 LOGE("memory alloc failed");
547 pkgmgrinfo_basic_free_application(app_info);
548 return PMINFO_R_ERROR;
552 app_info->background_category = g_list_copy_deep(data->background_category, __copy_str, &ret);
554 LOGE("memory alloc failed");
555 pkgmgrinfo_basic_free_application(app_info);
556 return PMINFO_R_ERROR;
560 app_info->splashscreens = g_list_copy_deep(data->splashscreens, __copy_splashscreens, &ret);
562 LOGE("memory alloc failed");
563 pkgmgrinfo_basic_free_application(app_info);
564 return PMINFO_R_ERROR;
567 *application = app_info;
572 API int pkgmgrinfo_appinfo_clone_appinfo(pkgmgrinfo_appinfo_h handle,
573 pkgmgrinfo_appinfo_h *clone)
575 pkgmgr_appinfo_x *info;
576 pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle;
579 return PMINFO_R_EINVAL;
581 info = calloc(1, sizeof(pkgmgr_appinfo_x));
583 LOGE("memory alloc failed");
584 return PMINFO_R_ERROR;
587 if (temp->package != NULL)
588 info->package = strdup(temp->package);
589 if (temp->locale != NULL)
590 info->locale = strdup(temp->locale);
592 info->app_component = temp->app_component;
594 if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) {
595 LOGE("appinfo copy failed");
597 free((void *)info->package);
601 return PMINFO_R_ERROR;
609 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
610 pkgmgrinfo_filter_x *filter, int flag, pkgmgrinfo_app_list_cb app_list_cb,
614 pkgmgr_appinfo_x info;
620 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
621 __free_applications);
623 return PMINFO_R_ERROR;
625 ret = _appinfo_get_applications(uid, uid, filter,
626 flag | PMINFO_APPINFO_GET_BASICINFO, list);
627 if (ret != PMINFO_R_OK) {
628 g_hash_table_destroy(list);
632 g_hash_table_iter_init(&iter, list);
633 while (g_hash_table_iter_next(&iter, NULL, &value)) {
634 app = (application_x *)value;
636 info.locale = info.app_info->locale;
637 info.package = app->package;
638 if (app_list_cb(&info, user_data) < 0)
641 g_hash_table_destroy(list);
646 static const char *__appcomponent_str(pkgmgrinfo_app_component comp);
648 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
649 pkgmgrinfo_app_component component,
650 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
653 pkgmgrinfo_appinfo_filter_h filter;
655 const char *comp_str = NULL;
657 if (handle == NULL || app_func == NULL) {
658 LOGE("invalid parameter");
659 return PMINFO_R_EINVAL;
662 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
663 LOGE("invalid parameter");
664 return PMINFO_R_EINVAL;
667 if (pkgmgrinfo_appinfo_filter_create(&filter))
668 return PMINFO_R_ERROR;
670 if (pkgmgrinfo_appinfo_filter_add_string(filter,
671 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
672 pkgmgrinfo_appinfo_filter_destroy(filter);
673 return PMINFO_R_ERROR;
676 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
677 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
678 pkgmgrinfo_appinfo_filter_destroy(filter);
679 return PMINFO_R_ERROR;
682 comp_str = __appcomponent_str(component);
685 if (pkgmgrinfo_appinfo_filter_add_string(filter,
686 PMINFO_APPINFO_PROP_APP_COMPONENT,
688 pkgmgrinfo_appinfo_filter_destroy(filter);
689 return PMINFO_R_ERROR;
693 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
694 PMINFO_APPINFO_GET_ALL, app_func, user_data);
696 pkgmgrinfo_appinfo_filter_destroy(filter);
701 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle,
702 pkgmgrinfo_app_component component,
703 pkgmgrinfo_app_list_cb app_func, void *user_data)
705 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, _getuid());
708 API int pkgmgrinfo_appinfo_get_usr_installed_list_full(
709 pkgmgrinfo_app_list_cb app_func, uid_t uid, int flag,
713 pkgmgrinfo_appinfo_filter_h filter;
715 if (app_func == NULL) {
716 LOGE("invalid parameter");
717 return PMINFO_R_EINVAL;
720 if (pkgmgrinfo_appinfo_filter_create(&filter))
721 return PMINFO_R_ERROR;
723 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
724 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
725 pkgmgrinfo_appinfo_filter_destroy(filter);
726 return PMINFO_R_ERROR;
729 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
730 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
731 pkgmgrinfo_appinfo_filter_destroy(filter);
732 return PMINFO_R_ERROR;
735 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
736 PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false)) {
737 pkgmgrinfo_appinfo_filter_destroy(filter);
738 return PMINFO_R_ERROR;
741 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, flag, app_func,
744 pkgmgrinfo_appinfo_filter_destroy(filter);
749 API int pkgmgrinfo_appinfo_get_installed_list_full(
750 pkgmgrinfo_app_list_cb app_func, int flag, void *user_data)
752 return pkgmgrinfo_appinfo_get_usr_installed_list_full(app_func,
753 _getuid(), flag, user_data);
756 API int pkgmgrinfo_appinfo_get_usr_installed_list(
757 pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
760 pkgmgrinfo_appinfo_filter_h filter;
762 if (app_func == NULL) {
763 LOGE("invalid parameter");
764 return PMINFO_R_EINVAL;
767 /* create an empty filter */
768 ret = pkgmgrinfo_appinfo_filter_create(&filter);
769 if (ret != PMINFO_R_OK)
772 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
773 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
774 pkgmgrinfo_appinfo_filter_destroy(filter);
775 return PMINFO_R_ERROR;
778 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
779 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
780 pkgmgrinfo_appinfo_filter_destroy(filter);
781 return PMINFO_R_ERROR;
784 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
785 PMINFO_APPINFO_GET_ALL, app_func, user_data);
787 pkgmgrinfo_appinfo_filter_destroy(filter);
792 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func,
795 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, _getuid(),
799 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
801 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
803 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
804 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
806 if (info->app_info == NULL || info->app_info->appid == NULL)
807 return PMINFO_R_ERROR;
808 *appid = (char *)info->app_info->appid;
813 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
815 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
817 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
818 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
820 if (info->package == NULL)
821 return PMINFO_R_ERROR;
823 *pkg_name = (char *)info->package;
828 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
830 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
832 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
833 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
835 if (info->package == NULL)
836 return PMINFO_R_ERROR;
838 *pkgid = (char *)info->package;
843 API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h handle, char **pkgtype)
845 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
846 retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
847 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
849 *pkgtype = (char *)info->app_info->package_type;
854 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
856 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
858 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
859 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
861 if (info->app_info == NULL || info->app_info->exec == NULL)
862 return PMINFO_R_ERROR;
863 *exec = (char *)info->app_info->exec;
869 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
872 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
874 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
875 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
877 if (info->app_info == NULL)
878 return PMINFO_R_ERROR;
880 if (info->app_info->icon == NULL) {
885 ptr = (icon_x *)info->app_info->icon->data;
887 return PMINFO_R_ERROR;
889 if (ptr->text == NULL)
890 return PMINFO_R_ERROR;
898 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
901 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
906 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
907 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
909 if (info->app_info == NULL)
910 return PMINFO_R_ERROR;
912 locale = info->locale;
914 locale = DEFAULT_LOCALE;
916 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
917 ptr = (label_x *)tmp->data;
918 if (ptr == NULL || strcmp(locale, ptr->lang) != 0)
929 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
930 ptr = (label_x *)tmp->data;
931 if (ptr == NULL || strcmp(DEFAULT_LOCALE, ptr->lang) != 0)
937 *label = lbl ? lbl : "";
942 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
946 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
947 val = _appinfo_get_localed_label(appid, locale, uid);
949 return PMINFO_R_ERROR;
955 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
957 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, _getuid(), label);
960 API int pkgmgrinfo_appinfo_get_metadata_value(pkgmgrinfo_appinfo_h handle, const char *metadata_key, char **metadata_value)
962 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
963 retvm_if(metadata_key == NULL, PMINFO_R_EINVAL, "metadata_key is NULL");
964 retvm_if(metadata_value == NULL, PMINFO_R_EINVAL, "metadata_value is NULL");
966 GList *list_md = NULL;
967 metadata_x *metadata = NULL;
968 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
970 list_md = info->app_info->metadata;
972 for (; list_md; list_md = list_md->next) {
973 metadata = (metadata_x *)list_md->data;
974 if (metadata && metadata->key) {
975 if (strcasecmp(metadata->key, metadata_key) == 0) {
976 if (metadata->value == NULL)
977 *metadata_value = "";
979 *metadata_value = (char *)metadata->value;
985 return PMINFO_R_EINVAL;
988 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
990 if (strcasecmp(comp, "uiapp") == 0)
991 return PMINFO_UI_APP;
992 else if (strcasecmp(comp, "svcapp") == 0)
993 return PMINFO_SVC_APP;
994 else if (strcasecmp(comp, "widgetapp") == 0)
995 return PMINFO_WIDGET_APP;
996 else if (strcasecmp(comp, "watchapp") == 0)
997 return PMINFO_WATCH_APP;
998 else if (strcasecmp(comp, "componentbasedapp") == 0)
999 return PMINFO_COMPONENT_BASED_APP;
1004 static const char *__appcomponent_str(pkgmgrinfo_app_component comp)
1009 case PMINFO_SVC_APP:
1011 case PMINFO_WIDGET_APP:
1013 case PMINFO_WATCH_APP:
1015 case PMINFO_COMPONENT_BASED_APP:
1016 return "componentbasedapp";
1022 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1024 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1027 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1028 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1030 if (info->app_info == NULL)
1031 return PMINFO_R_ERROR;
1033 comp = __appcomponent_convert(info->app_info->component);
1035 return PMINFO_R_ERROR;
1042 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1044 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1046 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1047 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1049 if (info->app_info == NULL || info->app_info->type == NULL)
1050 return PMINFO_R_ERROR;
1051 *app_type = (char *)info->app_info->type;
1056 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1061 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1063 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1064 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1066 if (info->app_info == NULL)
1067 return PMINFO_R_ERROR;
1069 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1070 ptr = (icon_x *)tmp->data;
1071 if (ptr == NULL || ptr->section == NULL)
1074 val = (char *)ptr->section;
1075 if (val && strcmp(val, "notification") == 0) {
1076 *icon = (char *)ptr->text;
1081 return PMINFO_R_ERROR;
1084 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1087 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1089 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1090 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1092 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1093 return PMINFO_R_ERROR;
1095 val = (char *)info->app_info->recentimage;
1096 if (strcasecmp(val, "capture") == 0)
1097 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1098 else if (strcasecmp(val, "icon") == 0)
1099 *type = PMINFO_RECENTIMAGE_USE_ICON;
1101 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1106 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1111 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1113 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1114 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1116 if (info->app_info == NULL)
1117 return PMINFO_R_ERROR;
1119 for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1120 ptr = (image_x *)tmp->data;
1121 if (ptr == NULL || ptr->section == NULL)
1124 val = (char *)ptr->section;
1125 if (val && strcmp(val, "preview") == 0) {
1126 *preview_img = (char *)ptr->text;
1131 return PMINFO_R_ERROR;
1134 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1137 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1139 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1140 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1142 val = info->app_info->permission_type;
1144 return PMINFO_R_ERROR;
1146 if (strcmp(val, "signature") == 0)
1147 *permission = PMINFO_PERMISSION_SIGNATURE;
1148 else if (strcmp(val, "privilege") == 0)
1149 *permission = PMINFO_PERMISSION_PRIVILEGE;
1151 *permission = PMINFO_PERMISSION_NORMAL;
1156 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1158 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1160 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1161 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1163 if (info->app_info == NULL || info->app_info->component_type == NULL)
1164 return PMINFO_R_ERROR;
1166 *component_type = (char *)info->app_info->component_type;
1171 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1174 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1176 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1177 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1179 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1180 return PMINFO_R_ERROR;
1182 val = (char *)info->app_info->hwacceleration;
1183 if (strcasecmp(val, "off") == 0)
1184 *hwacceleration = PMINFO_HWACCELERATION_OFF;
1185 else if (strcasecmp(val, "on") == 0)
1186 *hwacceleration = PMINFO_HWACCELERATION_ON;
1188 *hwacceleration = PMINFO_HWACCELERATION_DEFAULT;
1193 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1196 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1198 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1199 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1201 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1202 return PMINFO_R_ERROR;
1204 val = (char *)info->app_info->screenreader;
1205 if (strcasecmp(val, "screenreader-off") == 0)
1206 *screenreader = PMINFO_SCREENREADER_OFF;
1207 else if (strcasecmp(val, "screenreader-on") == 0)
1208 *screenreader = PMINFO_SCREENREADER_ON;
1210 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1215 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1217 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1219 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1220 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1221 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1223 if (info->app_info == NULL)
1224 return PMINFO_R_ERROR;
1226 if (info->app_info->portraitimg == NULL)
1229 *portrait_img = (char *)info->app_info->portraitimg;
1231 if (info->app_info->landscapeimg == NULL)
1232 *landscape_img = "";
1234 *landscape_img = (char *)info->app_info->landscapeimg;
1239 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
1241 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1243 if (handle == NULL || effectimage_type == NULL) {
1244 LOGE("invalid parameter");
1245 return PMINFO_R_EINVAL;
1248 if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
1249 return PMINFO_R_ERROR;
1251 *effectimage_type = (char *)info->app_info->effectimage_type;
1256 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
1258 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1260 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1261 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1263 if (info->app_info == NULL)
1264 return PMINFO_R_ERROR;
1266 if (info->app_info->submode_mainid == NULL)
1267 *submode_mainid = "";
1269 *submode_mainid = (char *)info->app_info->submode_mainid;
1274 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
1276 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1277 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1279 if (info->app_info && info->app_info->installed_storage) {
1280 if (strcmp(info->app_info->installed_storage, "installed_internal") == 0)
1281 *storage = PMINFO_INTERNAL_STORAGE;
1282 else if (strcmp(info->app_info->installed_storage, "installed_external") == 0)
1283 *storage = PMINFO_EXTERNAL_STORAGE;
1285 return PMINFO_R_ERROR;
1287 return PMINFO_R_ERROR;
1293 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
1295 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1297 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1298 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1300 if (info->app_info->launch_mode == NULL)
1301 return PMINFO_R_ERROR;
1303 *mode = (char *)(info->app_info->launch_mode);
1308 API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
1310 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1312 if (handle == NULL || alias_appid == NULL) {
1313 LOGE("invalid parameter");
1314 return PMINFO_R_EINVAL;
1317 if (info->app_info == NULL || info->app_info->alias_appid == NULL)
1318 return PMINFO_R_ERROR;
1320 *alias_appid = (char *)info->app_info->alias_appid;
1325 API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
1327 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1329 if (handle == NULL || effective_appid == NULL) {
1330 LOGE("invalid parameter");
1331 return PMINFO_R_EINVAL;
1334 if (info->app_info == NULL)
1335 return PMINFO_R_ERROR;
1337 if (info->app_info->effective_appid == NULL)
1338 *effective_appid = "";
1340 *effective_appid = (char *)info->app_info->effective_appid;
1345 API int pkgmgrinfo_appinfo_get_tep_name(pkgmgrinfo_appinfo_h handle, char **tep_name)
1347 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1349 if (handle == NULL || tep_name == NULL) {
1350 LOGE("invalid parameter");
1351 return PMINFO_R_EINVAL;
1354 if (info->app_info == NULL)
1355 return PMINFO_R_ERROR;
1357 if (info->app_info->tep_name == NULL)
1360 *tep_name = (char *)info->app_info->tep_name;
1365 API int pkgmgrinfo_appinfo_get_zip_mount_file(pkgmgrinfo_appinfo_h handle, char **zip_mount_file)
1367 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1369 if (handle == NULL || zip_mount_file == NULL) {
1370 LOGE("invalid parameter");
1371 return PMINFO_R_EINVAL;
1374 if (info->app_info == NULL)
1375 return PMINFO_R_ERROR;
1377 if (info->app_info->zip_mount_file == NULL)
1378 *zip_mount_file = "";
1380 *zip_mount_file = (char *)info->app_info->zip_mount_file;
1385 API int pkgmgrinfo_appinfo_get_root_path(pkgmgrinfo_appinfo_h handle, char **root_path)
1387 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1389 if (handle == NULL || root_path == NULL) {
1390 LOGE("invalid parameter");
1391 return PMINFO_R_EINVAL;
1394 if (info->app_info == NULL || info->app_info->root_path == NULL)
1395 return PMINFO_R_ERROR;
1397 *root_path = (char *)info->app_info->root_path;
1402 API int pkgmgrinfo_appinfo_get_api_version(pkgmgrinfo_appinfo_h handle, char **api_version)
1404 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1406 if (handle == NULL || api_version == NULL) {
1407 LOGE("invalid parameter");
1408 return PMINFO_R_EINVAL;
1411 if (info->app_info == NULL || info->app_info->api_version == NULL)
1412 return PMINFO_R_ERROR;
1414 *api_version = (char *)info->app_info->api_version;
1419 API int pkgmgrinfo_appinfo_get_installed_time(pkgmgrinfo_appinfo_h handle, int *installed_time)
1421 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1423 if (handle == NULL || installed_time == NULL) {
1424 LOGE("invalid parameter");
1425 return PMINFO_R_EINVAL;
1428 if (info->app_info == NULL || info->app_info->package_installed_time == NULL)
1429 return PMINFO_R_ERROR;
1431 *installed_time = atoi(info->app_info->package_installed_time);
1436 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid,
1437 const char *type, uid_t uid, char **appid, char **access)
1441 if (providerid == NULL || type == NULL || appid == NULL ||
1443 LOGE("invalid parameter");
1444 return PMINFO_R_EINVAL;
1447 ret = _appinfo_get_datacontrol_info(providerid, type, uid, appid, access);
1448 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
1449 * implementation, return PMINFO_R_ERROR. This should be
1452 if (ret == PMINFO_R_ENOENT) {
1453 LOGE("no datacontrol info of %s", providerid);
1454 ret = PMINFO_R_ERROR;
1460 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid,
1461 const char *type, char **appid, char **access)
1463 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid,
1464 type, _getuid(), appid, access);
1467 static int _appinfo_get_datacontrol_appid(const char *providerid,
1472 query = sqlite3_mprintf("SELECT app_id FROM package_app_data_control "
1473 "WHERE providerid=%Q", providerid);
1474 if (query == NULL) {
1475 LOGE("Out of memory");
1476 return PMINFO_R_ERROR;
1479 // TODO: change to use pkginfo-client APIs
1480 sqlite3_free(query);
1484 static int _pkgmgrinfo_appinfo_get_datacontrol_appid(uid_t uid,
1485 const char *providerid, char **appid)
1489 ret = _appinfo_get_datacontrol_appid(providerid, appid);
1493 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid,
1494 uid_t uid, char **appid)
1498 if (providerid == NULL || appid == NULL) {
1499 LOGE("invalid parameter");
1500 return PMINFO_R_EINVAL;
1503 ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(GLOBAL_USER, providerid,
1505 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
1506 ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(uid, providerid,
1509 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
1510 * implementation, return PMINFO_R_ERROR. This should be
1513 if (ret == PMINFO_R_ENOENT) {
1514 LOGE("no datacontrol appid of %s", providerid);
1515 ret = PMINFO_R_ERROR;
1521 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1523 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid);
1526 static int _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid_t uid,
1527 const char *providerid, const char *type, char **appid,
1532 query = sqlite3_mprintf(
1533 "SELECT app_id, trusted FROM package_app_data_control "
1534 "WHERE providerid=%Q AND type=%Q", providerid, type);
1538 // TODO: need to use pkginfo-client APIs
1539 sqlite3_free(query);
1543 API int pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(
1544 const char *providerid, const char *type, uid_t uid,
1545 char **appid, bool *is_trusted)
1549 if (providerid == NULL || type == NULL || appid == NULL ||
1550 is_trusted == NULL) {
1551 LOGE("invalid parameter");
1552 return PMINFO_R_EINVAL;
1555 ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(GLOBAL_USER,
1556 providerid, type, appid, is_trusted);
1557 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
1558 ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid,
1559 providerid, type, appid, is_trusted);
1561 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
1562 * implementation, return PMINFO_R_ERROR. This should be
1565 if (ret == PMINFO_R_ENOENT) {
1566 LOGE("no datacontrol trusted info of %s", providerid);
1567 ret = PMINFO_R_ERROR;
1573 API int pkgmgrinfo_appinfo_get_datacontrol_trsuted_info(const char *providerid,
1574 const char *type, char **appid, bool *is_trusted)
1576 return pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(providerid,
1577 type, _getuid(), appid, is_trusted);
1580 static int _appinfo_foreach_datacontrol_privileges(
1581 const char *providerid, const char *type,
1582 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
1586 query = sqlite3_mprintf(
1587 "SELECT privilege FROM package_app_data_control_privilege "
1588 "WHERE providerid=%Q AND type=%Q", providerid, type);
1589 if (query == NULL) {
1590 LOGE("Out of memory");
1591 return PMINFO_R_ERROR;
1594 // TODO: need to change to use pkginfo-client APIs
1595 sqlite3_free(query);
1599 static int _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid_t uid,
1600 const char *providerid, const char *type,
1601 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
1605 ret = _appinfo_foreach_datacontrol_privileges(providerid, type,
1606 callback, user_data);
1611 API int pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
1612 const char *providerid, const char *type,
1613 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
1614 void *user_data, uid_t uid)
1618 if (providerid == NULL || type == NULL || privilege_func == NULL) {
1619 LOGE("invalid parameter");
1620 return PMINFO_R_EINVAL;
1623 ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(GLOBAL_USER,
1624 providerid, type, privilege_func, user_data);
1625 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
1626 ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid,
1627 providerid, type, privilege_func, user_data);
1629 if (ret == PMINFO_R_ENOENT)
1635 API int pkgmgrinfo_appinfo_foreach_datacontrol_privileges(
1636 const char *providerid, const char *type,
1637 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
1640 return pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
1641 providerid, type, privilege_func, user_data, _getuid());
1644 API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h handle, int *support_mode)
1646 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1647 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1649 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1650 if (info->app_info->support_mode)
1651 *support_mode = atoi(info->app_info->support_mode);
1658 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
1659 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
1661 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1662 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1664 const char *category;
1666 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1668 if (info->app_info == NULL)
1669 return PMINFO_R_ERROR;
1671 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
1672 category = (const char *)tmp->data;
1674 ret = category_func(category, user_data);
1682 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
1683 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
1685 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1686 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1690 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1692 if (info->app_info == NULL)
1693 return PMINFO_R_ERROR;
1695 for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
1696 ptr = (metadata_x *)tmp->data;
1700 ret = metadata_func(ptr->key, ptr->value ? ptr->value : "", user_data);
1708 static int _appinfo_foreach_appcontrol_privileges(
1709 const char *appid, const char *operation,
1710 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
1714 query = sqlite3_mprintf(
1715 "SELECT app_control, privilege FROM package_app_app_control_privilege "
1716 "WHERE app_id=%Q", appid);
1717 if (query == NULL) {
1718 LOGE("Out of memory");
1719 return PMINFO_R_ERROR;
1722 // TODO: need to remove this codes and change to use pkginfo-client APIs
1723 sqlite3_free(query);
1727 static int _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid_t uid,
1728 const char *appid, const char *operation,
1729 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
1733 ret = _appinfo_foreach_appcontrol_privileges(appid, operation,
1734 callback, user_data);
1739 API int pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(const char *appid,
1740 const char *operation,
1741 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
1742 void *user_data, uid_t uid)
1746 if (appid == NULL || operation == NULL || privilege_func == NULL) {
1747 LOGE("invalid parameter");
1748 return PMINFO_R_EINVAL;
1751 ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(GLOBAL_USER,
1752 appid, operation, privilege_func, user_data);
1753 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
1754 ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid,
1755 appid, operation, privilege_func, user_data);
1757 if (ret == PMINFO_R_ENOENT)
1763 API int pkgmgrinfo_appinfo_foreach_appcontrol_privileges(const char *appid,
1764 const char *operation,
1765 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
1768 return pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(appid,
1769 operation, privilege_func, user_data, _getuid());
1772 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
1773 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1775 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1776 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1778 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1779 appcontrol_x *appcontrol;
1782 if (info->app_info == NULL)
1783 return PMINFO_R_ERROR;
1785 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
1786 appcontrol = (appcontrol_x *)tmp->data;
1787 if (appcontrol == NULL || !strcasecmp(appcontrol->visibility, "remote-only"))
1789 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1797 API int pkgmgrinfo_appinfo_foreach_remote_appcontrol(pkgmgrinfo_appinfo_h handle,
1798 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1800 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1801 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1803 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1804 appcontrol_x *appcontrol;
1807 if (info->app_info == NULL)
1808 return PMINFO_R_ERROR;
1810 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
1811 appcontrol = (appcontrol_x *)tmp->data;
1812 if (appcontrol == NULL || !strcasecmp(appcontrol->visibility, "local-only"))
1814 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1822 API int pkgmgrinfo_appinfo_foreach_background_category(
1823 pkgmgrinfo_appinfo_h handle,
1824 pkgmgrinfo_app_background_category_list_cb category_func,
1827 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1831 if (handle == NULL || category_func == NULL || info->app_info == NULL) {
1832 LOGE("invalid parameter");
1833 return PMINFO_R_EINVAL;
1836 for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
1837 category = (char *)tmp->data;
1838 if (category == NULL)
1841 if (category_func(category, user_data) < 0)
1848 API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
1849 pkgmgrinfo_app_splash_screen_list_cb splash_screen_func,
1852 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1853 splashscreen_x *splashscreen;
1857 if (info == NULL || info->app_info == NULL
1858 || splash_screen_func == NULL) {
1859 LOGE("invalid parameter");
1860 return PMINFO_R_EINVAL;
1863 for (tmp = info->app_info->splashscreens; tmp; tmp = tmp->next) {
1864 splashscreen = (splashscreen_x *)tmp->data;
1865 if (splashscreen == NULL)
1867 ret = splash_screen_func(splashscreen->src,
1869 splashscreen->orientation,
1870 splashscreen->indicatordisplay,
1871 splashscreen->operation,
1872 splashscreen->color_depth,
1881 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
1883 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1884 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1885 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1887 if (info->app_info == NULL || info->app_info->nodisplay == NULL)
1888 return PMINFO_R_ERROR;
1890 *nodisplay = _get_bool_value(info->app_info->nodisplay);
1895 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
1897 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1898 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1899 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1901 if (info->app_info == NULL || info->app_info->multiple == NULL)
1902 return PMINFO_R_ERROR;
1904 *multiple = _get_bool_value(info->app_info->multiple);
1909 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
1911 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1912 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1913 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1915 if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
1916 return PMINFO_R_ERROR;
1918 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
1923 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
1925 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1926 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1927 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1929 if (info->app_info == NULL || info->app_info->taskmanage == NULL)
1930 return PMINFO_R_ERROR;
1932 *taskmanage = _get_bool_value(info->app_info->taskmanage);
1937 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
1939 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1940 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1941 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1943 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
1944 return PMINFO_R_ERROR;
1946 *enabled = !_get_bool_value(info->app_info->is_disabled);
1951 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
1953 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1954 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1955 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1957 if (info->app_info == NULL || info->app_info->onboot == NULL)
1958 return PMINFO_R_ERROR;
1960 *onboot = _get_bool_value(info->app_info->onboot);
1965 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
1967 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1968 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1969 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1971 if (info->app_info == NULL || info->app_info->autorestart == NULL)
1972 return PMINFO_R_ERROR;
1974 *autorestart = _get_bool_value(info->app_info->autorestart);
1979 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
1981 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1982 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1983 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1985 if (info->app_info == NULL || info->app_info->mainapp == NULL)
1986 return PMINFO_R_ERROR;
1988 *mainapp = _get_bool_value(info->app_info->mainapp);
1993 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
1995 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1996 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1997 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1999 if (info->app_info == NULL || info->app_info->preload == NULL)
2000 return PMINFO_R_ERROR;
2002 *preload = _get_bool_value(info->app_info->preload);
2007 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
2009 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2010 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2011 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2013 if (info->app_info == NULL || info->app_info->submode == NULL)
2014 return PMINFO_R_ERROR;
2016 *submode = _get_bool_value(info->app_info->submode);
2021 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
2023 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2025 if (handle == NULL || process_pool == NULL) {
2026 LOGE("invalid parameter");
2027 return PMINFO_R_EINVAL;
2030 if (info->app_info == NULL)
2031 return PMINFO_R_ERROR;
2033 *process_pool = _get_bool_value(info->app_info->process_pool);
2038 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
2040 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2041 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
2042 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
2046 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2048 if (info->app_info == NULL)
2049 return PMINFO_R_ERROR;
2052 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2053 val = (const char *)tmp->data;
2056 if (strcasecmp(val, category) == 0) {
2065 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
2068 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2070 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
2071 _LOGE("invalid parameter");
2072 return PMINFO_R_EINVAL;
2074 if (info->app_info->ui_gadget == NULL)
2075 info->app_info->ui_gadget = strdup("false");
2077 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
2082 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
2083 bool *support_disable)
2085 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2087 if (info == NULL || info->app_info == NULL || support_disable == NULL) {
2088 _LOGE("invalid parameter");
2089 return PMINFO_R_EINVAL;
2092 *support_disable = _get_bool_value(info->app_info->support_disable);
2097 API int pkgmgrinfo_appinfo_is_removable(pkgmgrinfo_appinfo_h handle,
2100 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2102 if (info == NULL || info->app_info == NULL || removable == NULL) {
2103 _LOGE("invalid parameter");
2104 return PMINFO_R_EINVAL;
2107 *removable = _get_bool_value(info->app_info->removable);
2112 API int pkgmgrinfo_appinfo_is_system(pkgmgrinfo_appinfo_h handle, bool *system)
2114 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2116 if (info == NULL || info->app_info == NULL || system == NULL) {
2117 _LOGE("invalid parameter");
2118 return PMINFO_R_EINVAL;
2121 *system = _get_bool_value(info->app_info->package_system);
2126 API int pkgmgrinfo_appinfo_is_disabled(pkgmgrinfo_appinfo_h handle, bool *disabled)
2128 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2129 retvm_if(disabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2130 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2132 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
2133 return PMINFO_R_ERROR;
2135 *disabled = _get_bool_value(info->app_info->is_disabled);
2140 API int pkgmgrinfo_appinfo_is_global(pkgmgrinfo_appinfo_h handle, bool *global)
2142 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2144 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2145 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2147 if (info->app_info == NULL || info->app_info->for_all_users == NULL)
2148 return PMINFO_R_ERROR;
2150 *global = _get_bool_value(info->app_info->for_all_users);
2155 API int pkgmgrinfo_appinfo_get_splash_screen_display(pkgmgrinfo_appinfo_h handle, bool *splash_screen_display)
2157 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2159 if (info == NULL || splash_screen_display == NULL) {
2160 _LOGE("Invalid parameter");
2161 return PMINFO_R_EINVAL;
2164 if (info->app_info == NULL || info->app_info->splash_screen_display == NULL)
2165 return PMINFO_R_ERROR;
2167 *splash_screen_display = _get_bool_value(info->app_info->splash_screen_display);
2172 API int pkgmgrinfo_appinfo_get_setup_appid(pkgmgrinfo_appinfo_h handle, char **setup_appid)
2174 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2176 if (info == NULL || setup_appid == NULL) {
2177 _LOGE("Invalid parameter");
2178 return PMINFO_R_EINVAL;
2181 if (info->app_info == NULL || info->app_info->setup_appid == NULL)
2182 return PMINFO_R_ERROR;
2184 *setup_appid = info->app_info->setup_appid;
2188 API int pkgmgrinfo_appinfo_is_support_ambient(pkgmgrinfo_appinfo_h handle,
2189 bool *support_ambient)
2191 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2193 if (info == NULL || support_ambient == NULL) {
2194 _LOGE("Invalid parameter");
2195 return PMINFO_R_EINVAL;
2198 if (info->app_info == NULL || info->app_info->support_ambient == NULL)
2199 return PMINFO_R_ERROR;
2201 *support_ambient = _get_bool_value(info->app_info->support_ambient);
2206 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
2208 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2209 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2210 __cleanup_appinfo(info);
2214 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
2216 return (pkgmgrinfo_pkginfo_filter_create(handle));
2219 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
2221 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2224 static gint __compare_func(gconstpointer data1, gconstpointer data2)
2226 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
2227 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
2228 if (node1->prop == node2->prop)
2230 else if (node1->prop > node2->prop)
2236 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
2237 const char *property, const int value)
2239 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2240 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2241 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
2243 GSList *link = NULL;
2245 prop = _pminfo_appinfo_convert_to_prop_int(property);
2246 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
2247 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
2248 _LOGE("Invalid Integer Property\n");
2249 return PMINFO_R_EINVAL;
2251 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2252 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
2254 _LOGE("Out of Memory!!!\n");
2255 return PMINFO_R_ERROR;
2257 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
2258 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
2260 _LOGE("Out of Memory\n");
2263 return PMINFO_R_ERROR;
2267 /*If API is called multiple times for same property, we should override the previous values.
2268 Last value set will be used for filtering.*/
2269 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2271 filter->list = g_slist_delete_link(filter->list, link);
2272 filter->list = g_slist_append(filter->list, (gpointer)node);
2277 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
2278 const char *property, const bool value)
2280 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2281 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2283 GSList *link = NULL;
2285 prop = _pminfo_appinfo_convert_to_prop_bool(property);
2286 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
2287 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
2288 _LOGE("Invalid Boolean Property\n");
2289 return PMINFO_R_EINVAL;
2291 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2292 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
2294 _LOGE("Out of Memory!!!\n");
2295 return PMINFO_R_ERROR;
2298 val = strndup("true", 4);
2300 val = strndup("false", 5);
2302 _LOGE("Out of Memory\n");
2305 return PMINFO_R_ERROR;
2309 /*If API is called multiple times for same property, we should override the previous values.
2310 Last value set will be used for filtering.*/
2311 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2313 filter->list = g_slist_delete_link(filter->list, link);
2314 filter->list = g_slist_append(filter->list, (gpointer)node);
2319 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
2320 const char *property, const char *value)
2322 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2323 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2324 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2326 pkgmgrinfo_node_x *ptr = NULL;
2327 char prev[PKG_STRING_LEN_MAX] = {'\0'};
2328 char temp[PKG_STRING_LEN_MAX] = {'\0'};
2329 GSList *link = NULL;
2332 prop = _pminfo_appinfo_convert_to_prop_str(property);
2333 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
2334 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
2335 _LOGE("Invalid String Property\n");
2336 return PMINFO_R_EINVAL;
2338 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2339 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
2341 _LOGE("Out of Memory!!!\n");
2342 return PMINFO_R_ERROR;
2346 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
2347 node->value = strdup(value);
2348 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2350 filter->list = g_slist_delete_link(filter->list, link);
2351 filter->list = g_slist_append(filter->list, (gpointer)node);
2353 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
2354 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
2356 _LOGE("Out of Memory\n");
2359 return PMINFO_R_ERROR;
2361 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2363 ptr = (pkgmgrinfo_node_x *)link->data;
2364 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
2365 _LOGI("Previous value is %s\n", prev);
2366 filter->list = g_slist_delete_link(filter->list, link);
2367 ret = snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s,%s", prev, value);
2368 if (ret < 0 || ret > PKG_STRING_LEN_MAX - 1) {
2369 _LOGE("snprintf fail\n");
2372 return PMINFO_R_ERROR;
2374 strncpy(val, temp, PKG_STRING_LEN_MAX);
2375 _LOGI("New value is %s\n", val);
2377 filter->list = g_slist_append(filter->list, (gpointer)node);
2378 memset(temp, '\0', PKG_STRING_LEN_MAX);
2380 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s", value);
2381 strncpy(val, temp, PKG_STRING_LEN_MAX);
2382 _LOGI("First value is %s\n", val);
2384 filter->list = g_slist_append(filter->list, (gpointer)node);
2385 memset(temp, '\0', PKG_STRING_LEN_MAX);
2389 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
2390 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2392 filter->list = g_slist_delete_link(filter->list, link);
2393 filter->list = g_slist_append(filter->list, (gpointer)node);
2399 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
2403 if (handle == NULL || count == NULL) {
2404 _LOGE("invalid parameter");
2405 return PMINFO_R_EINVAL;
2408 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
2409 __free_applications);
2411 return PMINFO_R_ERROR;
2413 if (__check_disable_filter_exist(
2414 handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
2415 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
2416 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
2417 g_hash_table_destroy(list);
2418 return PMINFO_R_ERROR;
2422 if (__check_disable_filter_exist(
2423 handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
2424 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
2425 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
2426 g_hash_table_destroy(list);
2427 return PMINFO_R_ERROR;
2431 // TODO: use pkginfo-client APIs
2432 *count = g_hash_table_size(list);
2433 g_hash_table_destroy(list);
2438 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
2440 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, _getuid());
2443 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
2444 pkgmgrinfo_appinfo_filter_h handle,
2445 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2447 if (handle == NULL || app_cb == NULL) {
2448 LOGE("invalid parameter");
2449 return PMINFO_R_EINVAL;
2452 if (__check_disable_filter_exist(
2453 handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
2454 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
2455 PMINFO_APPINFO_PROP_APP_DISABLE, false))
2456 return PMINFO_R_ERROR;
2459 if (__check_disable_filter_exist(
2460 handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
2461 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
2462 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
2463 return PMINFO_R_ERROR;
2466 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
2470 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
2471 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2473 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, _getuid());
2476 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
2478 return (pkgmgrinfo_pkginfo_filter_create(handle));
2481 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
2483 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2486 API int pkgmgrinfo_appinfo_metadata_filter_add(
2487 pkgmgrinfo_appinfo_metadata_filter_h handle,
2488 const char *key, const char *value)
2490 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2491 pkgmgrinfo_metadata_node_x *node;
2493 /* value can be NULL.
2494 * In that case all apps with specified key should be displayed
2497 LOGE("invalid parameter");
2498 return PMINFO_R_EINVAL;
2501 node = calloc(1, sizeof(pkgmgrinfo_metadata_node_x));
2503 LOGE("out of memory");
2504 return PMINFO_R_ERROR;
2507 node->key = strdup(key);
2508 if (value && strlen(value))
2509 node->value = strdup(value);
2511 filter->list_metadata = g_slist_append(filter->list_metadata,
2517 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2518 pkgmgrinfo_appinfo_metadata_filter_h handle,
2519 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2521 if (handle == NULL || app_cb == NULL) {
2522 LOGE("invalid parameter");
2523 return PMINFO_R_EINVAL;
2526 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2527 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
2528 PMINFO_APPINFO_PROP_APP_DISABLE, false))
2529 return PMINFO_R_ERROR;
2531 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
2532 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
2533 return PMINFO_R_ERROR;
2535 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
2539 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
2540 pkgmgrinfo_appinfo_metadata_filter_h handle,
2541 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2543 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
2544 user_data, _getuid());
2547 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2550 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2552 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2553 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2555 val = info->app_info->guestmode_visibility;
2556 *status = _get_bool_value(val);
2560 API int pkgmgrinfo_appinfo_foreach_appcontrol_v2(pkgmgrinfo_appinfo_h handle,
2561 pkgmgrinfo_app_control_list_cb_v2 appcontrol_func,
2564 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2565 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2567 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2568 appcontrol_x *appcontrol;
2571 if (info->app_info == NULL)
2572 return PMINFO_R_ERROR;
2574 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2575 appcontrol = (appcontrol_x *)tmp->data;
2576 if (appcontrol == NULL ||
2577 !strcasecmp(appcontrol->visibility, "remote-only"))
2579 ret = appcontrol_func(appcontrol->operation, appcontrol->uri,
2580 appcontrol->mime, appcontrol->id, user_data);
2588 API int pkgmgrinfo_appinfo_foreach_remote_appcontrol_v2(
2589 pkgmgrinfo_appinfo_h handle,
2590 pkgmgrinfo_app_control_list_cb_v2 appcontrol_func,
2593 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2594 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2596 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2597 appcontrol_x *appcontrol;
2600 if (info->app_info == NULL)
2601 return PMINFO_R_ERROR;
2603 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2604 appcontrol = (appcontrol_x *)tmp->data;
2605 if (appcontrol == NULL ||
2606 !strcasecmp(appcontrol->visibility, "local-only"))
2608 ret = appcontrol_func(appcontrol->operation, appcontrol->uri,
2609 appcontrol->mime, appcontrol->id, user_data);