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 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid,
1468 uid_t uid, char **appid)
1471 if (providerid == NULL || appid == NULL) {
1472 LOGE("invalid parameter");
1473 return PMINFO_R_EINVAL;
1476 ret = _appinfo_get_datacontrol_appid(providerid, uid, appid);
1477 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
1478 * implementation, return PMINFO_R_ERROR. This should be
1481 if (ret == PMINFO_R_ENOENT) {
1482 LOGE("no datacontrol appid of %s", providerid);
1483 ret = PMINFO_R_ERROR;
1489 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1491 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid);
1494 API int pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(
1495 const char *providerid, const char *type, uid_t uid,
1496 char **appid, bool *is_trusted)
1499 char *trusted = NULL;
1500 if (providerid == NULL || type == NULL || appid == NULL ||
1501 is_trusted == NULL) {
1502 LOGE("invalid parameter");
1503 return PMINFO_R_EINVAL;
1506 ret = _appinfo_get_datacontrol_trusted_info(providerid, type, uid,
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 trusted info of %s", providerid);
1515 ret = PMINFO_R_ERROR;
1517 *is_trusted = _get_bool_value(trusted);
1523 API int pkgmgrinfo_appinfo_get_datacontrol_trsuted_info(const char *providerid,
1524 const char *type, char **appid, bool *is_trusted)
1526 return pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(providerid,
1527 type, _getuid(), appid, is_trusted);
1530 static int _appinfo_foreach_datacontrol_privileges(
1531 const char *providerid, const char *type,
1532 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
1536 query = sqlite3_mprintf(
1537 "SELECT privilege FROM package_app_data_control_privilege "
1538 "WHERE providerid=%Q AND type=%Q", providerid, type);
1539 if (query == NULL) {
1540 LOGE("Out of memory");
1541 return PMINFO_R_ERROR;
1544 // TODO: need to change to use pkginfo-client APIs
1545 sqlite3_free(query);
1549 static int _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid_t uid,
1550 const char *providerid, const char *type,
1551 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
1555 ret = _appinfo_foreach_datacontrol_privileges(providerid, type,
1556 callback, user_data);
1561 API int pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
1562 const char *providerid, const char *type,
1563 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
1564 void *user_data, uid_t uid)
1568 if (providerid == NULL || type == NULL || privilege_func == NULL) {
1569 LOGE("invalid parameter");
1570 return PMINFO_R_EINVAL;
1573 ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(GLOBAL_USER,
1574 providerid, type, privilege_func, user_data);
1575 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
1576 ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid,
1577 providerid, type, privilege_func, user_data);
1579 if (ret == PMINFO_R_ENOENT)
1585 API int pkgmgrinfo_appinfo_foreach_datacontrol_privileges(
1586 const char *providerid, const char *type,
1587 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
1590 return pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
1591 providerid, type, privilege_func, user_data, _getuid());
1594 API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h handle, int *support_mode)
1596 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1597 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1599 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1600 if (info->app_info->support_mode)
1601 *support_mode = atoi(info->app_info->support_mode);
1608 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
1609 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
1611 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1612 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1614 const char *category;
1616 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1618 if (info->app_info == NULL)
1619 return PMINFO_R_ERROR;
1621 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
1622 category = (const char *)tmp->data;
1624 ret = category_func(category, user_data);
1632 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
1633 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
1635 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1636 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1640 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1642 if (info->app_info == NULL)
1643 return PMINFO_R_ERROR;
1645 for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
1646 ptr = (metadata_x *)tmp->data;
1650 ret = metadata_func(ptr->key, ptr->value ? ptr->value : "", user_data);
1658 static int _appinfo_foreach_appcontrol_privileges(
1659 const char *appid, const char *operation,
1660 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
1664 query = sqlite3_mprintf(
1665 "SELECT app_control, privilege FROM package_app_app_control_privilege "
1666 "WHERE app_id=%Q", appid);
1667 if (query == NULL) {
1668 LOGE("Out of memory");
1669 return PMINFO_R_ERROR;
1672 // TODO: need to remove this codes and change to use pkginfo-client APIs
1673 sqlite3_free(query);
1677 static int _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid_t uid,
1678 const char *appid, const char *operation,
1679 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
1683 ret = _appinfo_foreach_appcontrol_privileges(appid, operation,
1684 callback, user_data);
1689 API int pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(const char *appid,
1690 const char *operation,
1691 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
1692 void *user_data, uid_t uid)
1696 if (appid == NULL || operation == NULL || privilege_func == NULL) {
1697 LOGE("invalid parameter");
1698 return PMINFO_R_EINVAL;
1701 ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(GLOBAL_USER,
1702 appid, operation, privilege_func, user_data);
1703 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
1704 ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid,
1705 appid, operation, privilege_func, user_data);
1707 if (ret == PMINFO_R_ENOENT)
1713 API int pkgmgrinfo_appinfo_foreach_appcontrol_privileges(const char *appid,
1714 const char *operation,
1715 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
1718 return pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(appid,
1719 operation, privilege_func, user_data, _getuid());
1722 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
1723 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1725 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1726 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1728 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1729 appcontrol_x *appcontrol;
1732 if (info->app_info == NULL)
1733 return PMINFO_R_ERROR;
1735 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
1736 appcontrol = (appcontrol_x *)tmp->data;
1737 if (appcontrol == NULL || !strcasecmp(appcontrol->visibility, "remote-only"))
1739 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1747 API int pkgmgrinfo_appinfo_foreach_remote_appcontrol(pkgmgrinfo_appinfo_h handle,
1748 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1750 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1751 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1753 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1754 appcontrol_x *appcontrol;
1757 if (info->app_info == NULL)
1758 return PMINFO_R_ERROR;
1760 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
1761 appcontrol = (appcontrol_x *)tmp->data;
1762 if (appcontrol == NULL || !strcasecmp(appcontrol->visibility, "local-only"))
1764 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1772 API int pkgmgrinfo_appinfo_foreach_background_category(
1773 pkgmgrinfo_appinfo_h handle,
1774 pkgmgrinfo_app_background_category_list_cb category_func,
1777 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1781 if (handle == NULL || category_func == NULL || info->app_info == NULL) {
1782 LOGE("invalid parameter");
1783 return PMINFO_R_EINVAL;
1786 for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
1787 category = (char *)tmp->data;
1788 if (category == NULL)
1791 if (category_func(category, user_data) < 0)
1798 API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
1799 pkgmgrinfo_app_splash_screen_list_cb splash_screen_func,
1802 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1803 splashscreen_x *splashscreen;
1807 if (info == NULL || info->app_info == NULL
1808 || splash_screen_func == NULL) {
1809 LOGE("invalid parameter");
1810 return PMINFO_R_EINVAL;
1813 for (tmp = info->app_info->splashscreens; tmp; tmp = tmp->next) {
1814 splashscreen = (splashscreen_x *)tmp->data;
1815 if (splashscreen == NULL)
1817 ret = splash_screen_func(splashscreen->src,
1819 splashscreen->orientation,
1820 splashscreen->indicatordisplay,
1821 splashscreen->operation,
1822 splashscreen->color_depth,
1831 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
1833 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1834 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1835 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1837 if (info->app_info == NULL || info->app_info->nodisplay == NULL)
1838 return PMINFO_R_ERROR;
1840 *nodisplay = _get_bool_value(info->app_info->nodisplay);
1845 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
1847 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1848 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1849 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1851 if (info->app_info == NULL || info->app_info->multiple == NULL)
1852 return PMINFO_R_ERROR;
1854 *multiple = _get_bool_value(info->app_info->multiple);
1859 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
1861 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1862 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1863 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1865 if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
1866 return PMINFO_R_ERROR;
1868 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
1873 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
1875 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1876 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1877 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1879 if (info->app_info == NULL || info->app_info->taskmanage == NULL)
1880 return PMINFO_R_ERROR;
1882 *taskmanage = _get_bool_value(info->app_info->taskmanage);
1887 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
1889 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1890 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1891 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1893 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
1894 return PMINFO_R_ERROR;
1896 *enabled = !_get_bool_value(info->app_info->is_disabled);
1901 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
1903 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1904 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1905 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1907 if (info->app_info == NULL || info->app_info->onboot == NULL)
1908 return PMINFO_R_ERROR;
1910 *onboot = _get_bool_value(info->app_info->onboot);
1915 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
1917 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1918 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1919 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1921 if (info->app_info == NULL || info->app_info->autorestart == NULL)
1922 return PMINFO_R_ERROR;
1924 *autorestart = _get_bool_value(info->app_info->autorestart);
1929 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
1931 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1932 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1933 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1935 if (info->app_info == NULL || info->app_info->mainapp == NULL)
1936 return PMINFO_R_ERROR;
1938 *mainapp = _get_bool_value(info->app_info->mainapp);
1943 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
1945 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1946 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1947 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1949 if (info->app_info == NULL || info->app_info->preload == NULL)
1950 return PMINFO_R_ERROR;
1952 *preload = _get_bool_value(info->app_info->preload);
1957 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
1959 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1960 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1961 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1963 if (info->app_info == NULL || info->app_info->submode == NULL)
1964 return PMINFO_R_ERROR;
1966 *submode = _get_bool_value(info->app_info->submode);
1971 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
1973 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1975 if (handle == NULL || process_pool == NULL) {
1976 LOGE("invalid parameter");
1977 return PMINFO_R_EINVAL;
1980 if (info->app_info == NULL)
1981 return PMINFO_R_ERROR;
1983 *process_pool = _get_bool_value(info->app_info->process_pool);
1988 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
1990 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1991 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
1992 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
1996 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1998 if (info->app_info == NULL)
1999 return PMINFO_R_ERROR;
2002 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2003 val = (const char *)tmp->data;
2006 if (strcasecmp(val, category) == 0) {
2015 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
2018 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2020 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
2021 _LOGE("invalid parameter");
2022 return PMINFO_R_EINVAL;
2024 if (info->app_info->ui_gadget == NULL)
2025 info->app_info->ui_gadget = strdup("false");
2027 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
2032 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
2033 bool *support_disable)
2035 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2037 if (info == NULL || info->app_info == NULL || support_disable == NULL) {
2038 _LOGE("invalid parameter");
2039 return PMINFO_R_EINVAL;
2042 *support_disable = _get_bool_value(info->app_info->support_disable);
2047 API int pkgmgrinfo_appinfo_is_removable(pkgmgrinfo_appinfo_h handle,
2050 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2052 if (info == NULL || info->app_info == NULL || removable == NULL) {
2053 _LOGE("invalid parameter");
2054 return PMINFO_R_EINVAL;
2057 *removable = _get_bool_value(info->app_info->removable);
2062 API int pkgmgrinfo_appinfo_is_system(pkgmgrinfo_appinfo_h handle, bool *system)
2064 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2066 if (info == NULL || info->app_info == NULL || system == NULL) {
2067 _LOGE("invalid parameter");
2068 return PMINFO_R_EINVAL;
2071 *system = _get_bool_value(info->app_info->package_system);
2076 API int pkgmgrinfo_appinfo_is_disabled(pkgmgrinfo_appinfo_h handle, bool *disabled)
2078 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2079 retvm_if(disabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2080 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2082 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
2083 return PMINFO_R_ERROR;
2085 *disabled = _get_bool_value(info->app_info->is_disabled);
2090 API int pkgmgrinfo_appinfo_is_global(pkgmgrinfo_appinfo_h handle, bool *global)
2092 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2094 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2095 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2097 if (info->app_info == NULL || info->app_info->for_all_users == NULL)
2098 return PMINFO_R_ERROR;
2100 *global = _get_bool_value(info->app_info->for_all_users);
2105 API int pkgmgrinfo_appinfo_get_splash_screen_display(pkgmgrinfo_appinfo_h handle, bool *splash_screen_display)
2107 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2109 if (info == NULL || splash_screen_display == NULL) {
2110 _LOGE("Invalid parameter");
2111 return PMINFO_R_EINVAL;
2114 if (info->app_info == NULL || info->app_info->splash_screen_display == NULL)
2115 return PMINFO_R_ERROR;
2117 *splash_screen_display = _get_bool_value(info->app_info->splash_screen_display);
2122 API int pkgmgrinfo_appinfo_get_setup_appid(pkgmgrinfo_appinfo_h handle, char **setup_appid)
2124 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2126 if (info == NULL || setup_appid == NULL) {
2127 _LOGE("Invalid parameter");
2128 return PMINFO_R_EINVAL;
2131 if (info->app_info == NULL || info->app_info->setup_appid == NULL)
2132 return PMINFO_R_ERROR;
2134 *setup_appid = info->app_info->setup_appid;
2138 API int pkgmgrinfo_appinfo_is_support_ambient(pkgmgrinfo_appinfo_h handle,
2139 bool *support_ambient)
2141 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2143 if (info == NULL || support_ambient == NULL) {
2144 _LOGE("Invalid parameter");
2145 return PMINFO_R_EINVAL;
2148 if (info->app_info == NULL || info->app_info->support_ambient == NULL)
2149 return PMINFO_R_ERROR;
2151 *support_ambient = _get_bool_value(info->app_info->support_ambient);
2156 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
2158 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2159 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2160 __cleanup_appinfo(info);
2164 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
2166 return (pkgmgrinfo_pkginfo_filter_create(handle));
2169 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
2171 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2174 static gint __compare_func(gconstpointer data1, gconstpointer data2)
2176 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
2177 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
2178 if (node1->prop == node2->prop)
2180 else if (node1->prop > node2->prop)
2186 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
2187 const char *property, const int value)
2189 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2190 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2191 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
2193 GSList *link = NULL;
2195 prop = _pminfo_appinfo_convert_to_prop_int(property);
2196 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
2197 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
2198 _LOGE("Invalid Integer Property\n");
2199 return PMINFO_R_EINVAL;
2201 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2202 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
2204 _LOGE("Out of Memory!!!\n");
2205 return PMINFO_R_ERROR;
2207 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
2208 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
2210 _LOGE("Out of Memory\n");
2213 return PMINFO_R_ERROR;
2217 /*If API is called multiple times for same property, we should override the previous values.
2218 Last value set will be used for filtering.*/
2219 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2221 filter->list = g_slist_delete_link(filter->list, link);
2222 filter->list = g_slist_append(filter->list, (gpointer)node);
2227 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
2228 const char *property, const bool value)
2230 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2231 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2233 GSList *link = NULL;
2235 prop = _pminfo_appinfo_convert_to_prop_bool(property);
2236 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
2237 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
2238 _LOGE("Invalid Boolean Property\n");
2239 return PMINFO_R_EINVAL;
2241 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2242 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
2244 _LOGE("Out of Memory!!!\n");
2245 return PMINFO_R_ERROR;
2248 val = strndup("true", 4);
2250 val = strndup("false", 5);
2252 _LOGE("Out of Memory\n");
2255 return PMINFO_R_ERROR;
2259 /*If API is called multiple times for same property, we should override the previous values.
2260 Last value set will be used for filtering.*/
2261 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2263 filter->list = g_slist_delete_link(filter->list, link);
2264 filter->list = g_slist_append(filter->list, (gpointer)node);
2269 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
2270 const char *property, const char *value)
2272 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2273 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2274 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2276 pkgmgrinfo_node_x *ptr = NULL;
2277 char prev[PKG_STRING_LEN_MAX] = {'\0'};
2278 char temp[PKG_STRING_LEN_MAX] = {'\0'};
2279 GSList *link = NULL;
2282 prop = _pminfo_appinfo_convert_to_prop_str(property);
2283 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
2284 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
2285 _LOGE("Invalid String Property\n");
2286 return PMINFO_R_EINVAL;
2288 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2289 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
2291 _LOGE("Out of Memory!!!\n");
2292 return PMINFO_R_ERROR;
2296 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
2297 node->value = strdup(value);
2298 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2300 filter->list = g_slist_delete_link(filter->list, link);
2301 filter->list = g_slist_append(filter->list, (gpointer)node);
2303 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
2304 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
2306 _LOGE("Out of Memory\n");
2309 return PMINFO_R_ERROR;
2311 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2313 ptr = (pkgmgrinfo_node_x *)link->data;
2314 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
2315 _LOGI("Previous value is %s\n", prev);
2316 filter->list = g_slist_delete_link(filter->list, link);
2317 ret = snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s,%s", prev, value);
2318 if (ret < 0 || ret > PKG_STRING_LEN_MAX - 1) {
2319 _LOGE("snprintf fail\n");
2322 return PMINFO_R_ERROR;
2324 strncpy(val, temp, PKG_STRING_LEN_MAX);
2325 _LOGI("New value is %s\n", val);
2327 filter->list = g_slist_append(filter->list, (gpointer)node);
2328 memset(temp, '\0', PKG_STRING_LEN_MAX);
2330 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s", value);
2331 strncpy(val, temp, PKG_STRING_LEN_MAX);
2332 _LOGI("First value is %s\n", val);
2334 filter->list = g_slist_append(filter->list, (gpointer)node);
2335 memset(temp, '\0', PKG_STRING_LEN_MAX);
2339 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
2340 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2342 filter->list = g_slist_delete_link(filter->list, link);
2343 filter->list = g_slist_append(filter->list, (gpointer)node);
2349 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
2353 if (handle == NULL || count == NULL) {
2354 _LOGE("invalid parameter");
2355 return PMINFO_R_EINVAL;
2358 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
2359 __free_applications);
2361 return PMINFO_R_ERROR;
2363 if (__check_disable_filter_exist(
2364 handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
2365 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
2366 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
2367 g_hash_table_destroy(list);
2368 return PMINFO_R_ERROR;
2372 if (__check_disable_filter_exist(
2373 handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
2374 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
2375 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
2376 g_hash_table_destroy(list);
2377 return PMINFO_R_ERROR;
2381 // TODO: use pkginfo-client APIs
2382 *count = g_hash_table_size(list);
2383 g_hash_table_destroy(list);
2388 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
2390 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, _getuid());
2393 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
2394 pkgmgrinfo_appinfo_filter_h handle,
2395 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2397 if (handle == NULL || app_cb == NULL) {
2398 LOGE("invalid parameter");
2399 return PMINFO_R_EINVAL;
2402 if (__check_disable_filter_exist(
2403 handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
2404 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
2405 PMINFO_APPINFO_PROP_APP_DISABLE, false))
2406 return PMINFO_R_ERROR;
2409 if (__check_disable_filter_exist(
2410 handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
2411 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
2412 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
2413 return PMINFO_R_ERROR;
2416 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
2420 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
2421 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2423 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, _getuid());
2426 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
2428 return (pkgmgrinfo_pkginfo_filter_create(handle));
2431 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
2433 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2436 API int pkgmgrinfo_appinfo_metadata_filter_add(
2437 pkgmgrinfo_appinfo_metadata_filter_h handle,
2438 const char *key, const char *value)
2440 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2441 pkgmgrinfo_metadata_node_x *node;
2443 /* value can be NULL.
2444 * In that case all apps with specified key should be displayed
2447 LOGE("invalid parameter");
2448 return PMINFO_R_EINVAL;
2451 node = calloc(1, sizeof(pkgmgrinfo_metadata_node_x));
2453 LOGE("out of memory");
2454 return PMINFO_R_ERROR;
2457 node->key = strdup(key);
2458 if (value && strlen(value))
2459 node->value = strdup(value);
2461 filter->list_metadata = g_slist_append(filter->list_metadata,
2467 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2468 pkgmgrinfo_appinfo_metadata_filter_h handle,
2469 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2471 if (handle == NULL || app_cb == NULL) {
2472 LOGE("invalid parameter");
2473 return PMINFO_R_EINVAL;
2476 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2477 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
2478 PMINFO_APPINFO_PROP_APP_DISABLE, false))
2479 return PMINFO_R_ERROR;
2481 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
2482 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
2483 return PMINFO_R_ERROR;
2485 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
2489 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
2490 pkgmgrinfo_appinfo_metadata_filter_h handle,
2491 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2493 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
2494 user_data, _getuid());
2497 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2500 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2502 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2503 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2505 val = info->app_info->guestmode_visibility;
2506 *status = _get_bool_value(val);
2510 API int pkgmgrinfo_appinfo_foreach_appcontrol_v2(pkgmgrinfo_appinfo_h handle,
2511 pkgmgrinfo_app_control_list_cb_v2 appcontrol_func,
2514 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2515 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2517 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2518 appcontrol_x *appcontrol;
2521 if (info->app_info == NULL)
2522 return PMINFO_R_ERROR;
2524 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2525 appcontrol = (appcontrol_x *)tmp->data;
2526 if (appcontrol == NULL ||
2527 !strcasecmp(appcontrol->visibility, "remote-only"))
2529 ret = appcontrol_func(appcontrol->operation, appcontrol->uri,
2530 appcontrol->mime, appcontrol->id, user_data);
2538 API int pkgmgrinfo_appinfo_foreach_remote_appcontrol_v2(
2539 pkgmgrinfo_appinfo_h handle,
2540 pkgmgrinfo_app_control_list_cb_v2 appcontrol_func,
2543 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2544 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2546 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2547 appcontrol_x *appcontrol;
2550 if (info->app_info == NULL)
2551 return PMINFO_R_ERROR;
2553 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2554 appcontrol = (appcontrol_x *)tmp->data;
2555 if (appcontrol == NULL ||
2556 !strcasecmp(appcontrol->visibility, "local-only"))
2558 ret = appcontrol_func(appcontrol->operation, appcontrol->uri,
2559 appcontrol->mime, appcontrol->id, user_data);