13 #include "pkgmgr-info.h"
14 #include "pkgmgrinfo_debug.h"
15 #include "pkgmgrinfo_private.h"
16 #include "pkgmgr_parser.h"
18 static bool _get_bool_value(const char *str)
20 if (str && !strcmp(str, "true"))
26 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
28 pkgmgr_appinfo_x *info = data;
32 free((void *)info->package);
34 free((void *)info->locale);
36 pkgmgrinfo_basic_free_application(info->app_info);
42 static void __free_applications(gpointer data)
44 pkgmgrinfo_basic_free_application((application_x *)data);
47 static gint __disable_chk_func(gconstpointer data1, gconstpointer data2)
49 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1;
50 pkgmgrinfo_appinfo_disable_type value = GPOINTER_TO_INT(data2);
52 if (value == E_APPINFO_DISABLE_TYPE_PKG)
53 return (node->prop == E_PMINFO_APPINFO_PROP_PKG_DISABLE)
56 return (node->prop == E_PMINFO_APPINFO_PROP_APP_DISABLE)
60 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter,
61 pkgmgrinfo_appinfo_disable_type type)
68 link = g_slist_find_custom(filter->list, GINT_TO_POINTER(type), __disable_chk_func);
75 static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
76 pkgmgrinfo_appinfo_filter_h filter, pkgmgrinfo_appinfo_h *handle)
78 int ret = PMINFO_R_OK;
80 pkgmgr_appinfo_x *info;
82 if (appid == NULL || filter == NULL || handle == NULL) {
83 LOGE("invalid parameter");
84 return PMINFO_R_EINVAL;
87 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
90 return PMINFO_R_ERROR;
92 // TODO: need to use pkginfo-client APIs
94 if (!g_hash_table_size(list)) {
95 _LOGD("appinfo for [%s] is not existed for user [%d]",
97 g_hash_table_destroy(list);
98 return PMINFO_R_ENOENT;
101 info = calloc(1, sizeof(pkgmgr_appinfo_x));
103 _LOGE("out of memory");
104 g_hash_table_destroy(list);
105 return PMINFO_R_ERROR;
108 info->app_info = (application_x *)g_hash_table_lookup(list, appid);
109 if (!info->app_info || !info->app_info->package) {
110 _LOGD("appinfo for [%s] is not existed for user [%d]",
112 g_hash_table_destroy(list);
114 return PMINFO_R_ENOENT;
116 //info->locale = locale;
117 info->package = strdup(info->app_info->package);
118 if (!info->package) {
119 _LOGE("out of memory");
120 g_hash_table_destroy(list);
122 return PMINFO_R_ERROR;
125 /* just free list only */
126 g_hash_table_steal(list, (gconstpointer)appid);
127 g_hash_table_destroy(list);
134 API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid,
135 pkgmgrinfo_appinfo_h *handle)
138 pkgmgrinfo_appinfo_filter_h filter;
140 if (appid == NULL || handle == NULL) {
141 LOGE("invalid parameter");
142 return PMINFO_R_EINVAL;
145 ret = pkgmgrinfo_appinfo_filter_create(&filter);
146 if (ret != PMINFO_R_OK)
149 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
150 PMINFO_APPINFO_PROP_APP_ID, appid);
151 if (ret != PMINFO_R_OK) {
152 pkgmgrinfo_appinfo_filter_destroy(filter);
153 return PMINFO_R_ERROR;
156 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
157 PMINFO_APPINFO_PROP_APP_DISABLE, true);
158 if (ret != PMINFO_R_OK) {
159 pkgmgrinfo_appinfo_filter_destroy(filter);
160 return PMINFO_R_ERROR;
163 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
164 pkgmgrinfo_appinfo_filter_destroy(filter);
169 API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
171 return pkgmgrinfo_appinfo_get_usr_disabled_appinfo(appid, _getuid(), handle);
174 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
175 pkgmgrinfo_appinfo_h *handle)
178 pkgmgrinfo_appinfo_filter_h filter;
180 if (appid == NULL || handle == NULL) {
181 LOGE("invalid parameter");
182 return PMINFO_R_EINVAL;
185 ret = pkgmgrinfo_appinfo_filter_create(&filter);
186 if (ret != PMINFO_R_OK)
189 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
190 PMINFO_APPINFO_PROP_APP_ID, appid);
191 if (ret != PMINFO_R_OK) {
192 pkgmgrinfo_appinfo_filter_destroy(filter);
193 return PMINFO_R_ERROR;
196 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
197 PMINFO_APPINFO_PROP_APP_DISABLE, false);
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_PKG_DISABLE, false);
205 if (ret != PMINFO_R_OK) {
206 pkgmgrinfo_appinfo_filter_destroy(filter);
207 return PMINFO_R_ERROR;
210 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
211 pkgmgrinfo_appinfo_filter_destroy(filter);
215 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
217 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, _getuid(), handle);
220 API int pkgmgrinfo_appinfo_get_usr_all_appinfo(const char *appid, uid_t uid,
221 pkgmgrinfo_appinfo_h *handle)
224 pkgmgrinfo_appinfo_filter_h filter;
226 if (appid == NULL || handle == NULL) {
227 LOGE("invalid parameter");
228 return PMINFO_R_EINVAL;
231 ret = pkgmgrinfo_appinfo_filter_create(&filter);
232 if (ret != PMINFO_R_OK)
235 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
236 PMINFO_APPINFO_PROP_APP_ID, appid);
237 if (ret != PMINFO_R_OK) {
238 pkgmgrinfo_appinfo_filter_destroy(filter);
239 return PMINFO_R_ERROR;
242 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
243 PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false);
244 if (ret != PMINFO_R_OK) {
245 pkgmgrinfo_appinfo_filter_destroy(filter);
246 return PMINFO_R_ERROR;
249 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
250 pkgmgrinfo_appinfo_filter_destroy(filter);
255 API int pkgmgrinfo_appinfo_get_all_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
257 return pkgmgrinfo_appinfo_get_usr_all_appinfo(appid, _getuid(), handle);
260 static gpointer __copy_str(gconstpointer src, gpointer data)
262 const char *tmp = (const char *)src;
265 buffer = strdup(tmp);
266 if (buffer == NULL) {
267 LOGE("memory alloc failed");
275 static gpointer __copy_label(gconstpointer src, gpointer data)
277 label_x *tmp = (label_x *)src;
280 label = calloc(1, sizeof(label_x));
282 LOGE("memory alloc failed");
288 label->name = strdup(tmp->name);
290 label->text = strdup(tmp->text);
292 label->lang = strdup(tmp->lang);
297 static gpointer __copy_icon(gconstpointer src, gpointer data)
299 icon_x *tmp = (icon_x *)src;
302 icon = calloc(1, sizeof(icon_x));
304 LOGE("memory alloc failed");
310 icon->text = strdup(tmp->text);
312 icon->lang = strdup(tmp->lang);
314 icon->section = strdup(tmp->section);
316 icon->size = strdup(tmp->size);
318 icon->resolution = strdup(tmp->resolution);
323 static gpointer __copy_metadata(gconstpointer src, gpointer data)
325 metadata_x *tmp = (metadata_x *)src;
326 metadata_x *metadata;
328 metadata = calloc(1, sizeof(metadata_x));
329 if (metadata == NULL) {
330 LOGE("memory alloc failed");
336 metadata->key = strdup(tmp->key);
338 metadata->value = strdup(tmp->value);
343 static gpointer __copy_datacontrol(gconstpointer src, gpointer data)
345 datacontrol_x *tmp = (datacontrol_x *)src;
346 datacontrol_x *datacontrol;
348 datacontrol = calloc(1, sizeof(datacontrol_x));
349 if (datacontrol == NULL) {
350 LOGE("memory alloc failed");
356 datacontrol->providerid = strdup(tmp->providerid);
358 datacontrol->access = strdup(tmp->access);
360 datacontrol->type = strdup(tmp->type);
362 datacontrol->trusted = strdup(tmp->trusted);
367 static gpointer __copy_appcontrol(gconstpointer src, gpointer data)
369 appcontrol_x *tmp = (appcontrol_x *)src;
370 appcontrol_x *appcontrol;
372 appcontrol = calloc(1, sizeof(appcontrol_x));
373 if (appcontrol == NULL) {
374 LOGE("memory alloc failed");
380 appcontrol->operation = strdup(tmp->operation);
382 appcontrol->uri = strdup(tmp->uri);
384 appcontrol->mime = strdup(tmp->mime);
389 static gpointer __copy_splashscreens(gconstpointer src, gpointer data)
391 splashscreen_x *tmp = (splashscreen_x *)src;
392 splashscreen_x *splashscreen;
394 splashscreen = (splashscreen_x *)calloc(1, sizeof(splashscreen_x));
395 if (splashscreen == NULL) {
396 LOGE("memory alloc failed");
402 splashscreen->src = strdup(tmp->src);
404 splashscreen->type = strdup(tmp->type);
405 if (tmp->orientation)
406 splashscreen->orientation = strdup(tmp->orientation);
407 if (tmp->indicatordisplay)
408 splashscreen->indicatordisplay = strdup(tmp->indicatordisplay);
410 splashscreen->operation = strdup(tmp->operation);
411 if (tmp->color_depth)
412 splashscreen->color_depth = strdup(tmp->color_depth);
417 static int _appinfo_copy_appinfo(application_x **application, application_x *data)
419 application_x *app_info;
422 app_info = calloc(1, sizeof(application_x));
423 if (app_info == NULL) {
424 LOGE("memory alloc failed");
425 return PMINFO_R_ERROR;
428 if (data->appid != NULL)
429 app_info->appid = strdup(data->appid);
430 if (data->exec != NULL)
431 app_info->exec = strdup(data->exec);
432 if (data->nodisplay != NULL)
433 app_info->nodisplay = strdup(data->nodisplay);
434 if (data->multiple != NULL)
435 app_info->multiple = strdup(data->multiple);
436 if (data->taskmanage != NULL)
437 app_info->taskmanage = strdup(data->taskmanage);
438 if (data->type != NULL)
439 app_info->type = strdup(data->type);
440 if (data->categories != NULL)
441 app_info->categories = strdup(data->categories);
442 if (data->hwacceleration != NULL)
443 app_info->hwacceleration = strdup(data->hwacceleration);
444 if (data->screenreader != NULL)
445 app_info->screenreader = strdup(data->screenreader);
446 if (data->mainapp != NULL)
447 app_info->mainapp = strdup(data->mainapp);
448 if (data->package != NULL)
449 app_info->package = strdup(data->package);
450 if (data->recentimage != NULL)
451 app_info->recentimage = strdup(data->recentimage);
452 if (data->launchcondition != NULL)
453 app_info->launchcondition = strdup(data->launchcondition);
454 if (data->indicatordisplay != NULL)
455 app_info->indicatordisplay = strdup(data->indicatordisplay);
456 if (data->portraitimg != NULL)
457 app_info->portraitimg = strdup(data->portraitimg);
458 if (data->landscapeimg != NULL)
459 app_info->landscapeimg = strdup(data->landscapeimg);
460 if (data->guestmode_visibility != NULL)
461 app_info->guestmode_visibility = strdup(data->guestmode_visibility);
462 if (data->component != NULL)
463 app_info->component = strdup(data->component);
464 if (data->permission_type != NULL)
465 app_info->permission_type = strdup(data->permission_type);
466 if (data->component_type != NULL)
467 app_info->component_type = strdup(data->component_type);
468 if (data->preload != NULL)
469 app_info->preload = strdup(data->preload);
470 if (data->submode != NULL)
471 app_info->submode = strdup(data->submode);
472 if (data->submode_mainid != NULL)
473 app_info->submode_mainid = strdup(data->submode_mainid);
474 if (data->process_pool != NULL)
475 app_info->process_pool = strdup(data->process_pool);
476 if (data->installed_storage != NULL)
477 app_info->installed_storage = strdup(data->installed_storage);
478 if (data->autorestart != NULL)
479 app_info->autorestart = strdup(data->autorestart);
480 if (data->onboot != NULL)
481 app_info->onboot = strdup(data->onboot);
482 if (data->support_disable != NULL)
483 app_info->support_disable = strdup(data->support_disable);
484 if (data->ui_gadget != NULL)
485 app_info->ui_gadget = strdup(data->ui_gadget);
486 if (data->launch_mode != NULL)
487 app_info->launch_mode = strdup(data->launch_mode);
488 if (data->package_type != NULL)
489 app_info->package_type = strdup(data->package_type);
490 if (data->effective_appid != NULL)
491 app_info->effective_appid = strdup(data->effective_appid);
492 if (data->splash_screen_display != NULL)
493 app_info->splash_screen_display = strdup(data->splash_screen_display);
497 app_info->label = g_list_copy_deep(data->label, __copy_label, &ret);
499 LOGE("memory alloc failed");
500 pkgmgrinfo_basic_free_application(app_info);
501 return PMINFO_R_ERROR;
505 app_info->icon = g_list_copy_deep(data->icon, __copy_icon, &ret);
507 LOGE("memory alloc failed");
508 pkgmgrinfo_basic_free_application(app_info);
509 return PMINFO_R_ERROR;
513 app_info->category = g_list_copy_deep(data->category, __copy_str, &ret);
515 LOGE("memory alloc failed");
516 pkgmgrinfo_basic_free_application(app_info);
517 return PMINFO_R_ERROR;
521 app_info->metadata = g_list_copy_deep(data->metadata, __copy_metadata, &ret);
523 LOGE("memory alloc failed");
524 pkgmgrinfo_basic_free_application(app_info);
525 return PMINFO_R_ERROR;
529 app_info->datacontrol = g_list_copy_deep(data->datacontrol, __copy_datacontrol, &ret);
531 LOGE("memory alloc failed");
532 pkgmgrinfo_basic_free_application(app_info);
533 return PMINFO_R_ERROR;
537 app_info->appcontrol = g_list_copy_deep(data->appcontrol, __copy_appcontrol, &ret);
539 LOGE("memory alloc failed");
540 pkgmgrinfo_basic_free_application(app_info);
541 return PMINFO_R_ERROR;
545 app_info->background_category = g_list_copy_deep(data->background_category, __copy_str, &ret);
547 LOGE("memory alloc failed");
548 pkgmgrinfo_basic_free_application(app_info);
549 return PMINFO_R_ERROR;
553 app_info->splashscreens = g_list_copy_deep(data->splashscreens, __copy_splashscreens, &ret);
555 LOGE("memory alloc failed");
556 pkgmgrinfo_basic_free_application(app_info);
557 return PMINFO_R_ERROR;
560 *application = app_info;
565 API int pkgmgrinfo_appinfo_clone_appinfo(pkgmgrinfo_appinfo_h handle,
566 pkgmgrinfo_appinfo_h *clone)
568 pkgmgr_appinfo_x *info;
569 pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle;
572 return PMINFO_R_EINVAL;
574 info = calloc(1, sizeof(pkgmgr_appinfo_x));
576 LOGE("memory alloc failed");
577 return PMINFO_R_ERROR;
580 if (temp->package != NULL)
581 info->package = strdup(temp->package);
582 if (temp->locale != NULL)
583 info->locale = strdup(temp->locale);
585 info->app_component = temp->app_component;
587 if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) {
588 LOGE("appinfo copy failed");
590 free((void *)info->package);
594 return PMINFO_R_ERROR;
602 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
603 pkgmgrinfo_filter_x *filter, int flag, pkgmgrinfo_app_list_cb app_list_cb,
607 pkgmgr_appinfo_x info;
612 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
613 __free_applications);
615 return PMINFO_R_ERROR;
617 // TODO: use pkginfo-client APIs to get appinfo
618 g_hash_table_iter_init(&iter, list);
619 while (g_hash_table_iter_next(&iter, NULL, &value)) {
620 app = (application_x *)value;
622 //info.locale = locale;
623 info.package = app->package;
624 if (app_list_cb(&info, user_data) < 0)
627 g_hash_table_destroy(list);
632 static const char *__appcomponent_str(pkgmgrinfo_app_component comp);
634 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
635 pkgmgrinfo_app_component component,
636 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
639 pkgmgrinfo_appinfo_filter_h filter;
641 const char *comp_str = NULL;
643 if (handle == NULL || app_func == NULL) {
644 LOGE("invalid parameter");
645 return PMINFO_R_EINVAL;
648 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
649 LOGE("invalid parameter");
650 return PMINFO_R_EINVAL;
653 if (pkgmgrinfo_appinfo_filter_create(&filter))
654 return PMINFO_R_ERROR;
656 if (pkgmgrinfo_appinfo_filter_add_string(filter,
657 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
658 pkgmgrinfo_appinfo_filter_destroy(filter);
659 return PMINFO_R_ERROR;
662 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
663 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
664 pkgmgrinfo_appinfo_filter_destroy(filter);
665 return PMINFO_R_ERROR;
668 comp_str = __appcomponent_str(component);
671 if (pkgmgrinfo_appinfo_filter_add_string(filter,
672 PMINFO_APPINFO_PROP_APP_COMPONENT,
674 pkgmgrinfo_appinfo_filter_destroy(filter);
675 return PMINFO_R_ERROR;
679 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
680 PMINFO_APPINFO_GET_ALL, app_func, user_data);
682 pkgmgrinfo_appinfo_filter_destroy(filter);
687 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle,
688 pkgmgrinfo_app_component component,
689 pkgmgrinfo_app_list_cb app_func, void *user_data)
691 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, _getuid());
694 API int pkgmgrinfo_appinfo_get_usr_installed_list_full(
695 pkgmgrinfo_app_list_cb app_func, uid_t uid, int flag,
699 pkgmgrinfo_appinfo_filter_h filter;
701 if (app_func == NULL) {
702 LOGE("invalid parameter");
703 return PMINFO_R_EINVAL;
706 if (pkgmgrinfo_appinfo_filter_create(&filter))
707 return PMINFO_R_ERROR;
709 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
710 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
711 pkgmgrinfo_appinfo_filter_destroy(filter);
712 return PMINFO_R_ERROR;
715 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
716 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
717 pkgmgrinfo_appinfo_filter_destroy(filter);
718 return PMINFO_R_ERROR;
721 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
722 PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false)) {
723 pkgmgrinfo_appinfo_filter_destroy(filter);
724 return PMINFO_R_ERROR;
727 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, flag, app_func,
730 pkgmgrinfo_appinfo_filter_destroy(filter);
735 API int pkgmgrinfo_appinfo_get_installed_list_full(
736 pkgmgrinfo_app_list_cb app_func, int flag, void *user_data)
738 return pkgmgrinfo_appinfo_get_usr_installed_list_full(app_func,
739 _getuid(), flag, user_data);
742 API int pkgmgrinfo_appinfo_get_usr_installed_list(
743 pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
746 pkgmgrinfo_appinfo_filter_h filter;
748 if (app_func == NULL) {
749 LOGE("invalid parameter");
750 return PMINFO_R_EINVAL;
753 /* create an empty filter */
754 ret = pkgmgrinfo_appinfo_filter_create(&filter);
755 if (ret != PMINFO_R_OK)
758 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
759 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
760 pkgmgrinfo_appinfo_filter_destroy(filter);
761 return PMINFO_R_ERROR;
764 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
765 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
766 pkgmgrinfo_appinfo_filter_destroy(filter);
767 return PMINFO_R_ERROR;
770 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
771 PMINFO_APPINFO_GET_ALL, app_func, user_data);
773 pkgmgrinfo_appinfo_filter_destroy(filter);
778 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func,
781 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, _getuid(),
785 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
787 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
789 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
790 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
792 if (info->app_info == NULL || info->app_info->appid == NULL)
793 return PMINFO_R_ERROR;
794 *appid = (char *)info->app_info->appid;
799 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
801 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
803 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
804 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
806 if (info->package == NULL)
807 return PMINFO_R_ERROR;
809 *pkg_name = (char *)info->package;
814 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
816 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
818 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
819 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
821 if (info->package == NULL)
822 return PMINFO_R_ERROR;
824 *pkgid = (char *)info->package;
829 API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h handle, char **pkgtype)
831 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
832 retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
833 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
835 *pkgtype = (char *)info->app_info->package_type;
840 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
842 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
844 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
845 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
847 if (info->app_info == NULL || info->app_info->exec == NULL)
848 return PMINFO_R_ERROR;
849 *exec = (char *)info->app_info->exec;
855 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
858 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
860 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
861 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
863 if (info->app_info == NULL)
864 return PMINFO_R_ERROR;
866 if (info->app_info->icon == NULL) {
871 ptr = (icon_x *)info->app_info->icon->data;
873 return PMINFO_R_ERROR;
875 if (ptr->text == NULL)
876 return PMINFO_R_ERROR;
884 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
887 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
892 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
893 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
895 if (info->app_info == NULL)
896 return PMINFO_R_ERROR;
898 locale = info->locale;
900 locale = DEFAULT_LOCALE;
902 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
903 ptr = (label_x *)tmp->data;
904 if (ptr == NULL || strcmp(locale, ptr->lang) != 0)
915 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
916 ptr = (label_x *)tmp->data;
917 if (ptr == NULL || strcmp(DEFAULT_LOCALE, ptr->lang) != 0)
923 *label = lbl ? lbl : "";
928 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
932 query = sqlite3_mprintf(
933 "SELECT app_label FROM package_app_localized_info "
934 "WHERE app_id=%Q AND app_locale=%Q", appid, locale);
936 _LOGE("Out of memory");
940 // TODO: need to use pkginfo-client APIs
945 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
949 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
951 val = _get_localed_label(appid, locale, uid);
953 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
956 val = _get_localed_label(appid, locale, GLOBAL_USER);
958 val = _get_localed_label(appid, DEFAULT_LOCALE, GLOBAL_USER);
962 return PMINFO_R_ERROR;
969 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
971 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, _getuid(), label);
974 API int pkgmgrinfo_appinfo_get_metadata_value(pkgmgrinfo_appinfo_h handle, const char *metadata_key, char **metadata_value)
976 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
977 retvm_if(metadata_key == NULL, PMINFO_R_EINVAL, "metadata_key is NULL");
978 retvm_if(metadata_value == NULL, PMINFO_R_EINVAL, "metadata_value is NULL");
980 GList *list_md = NULL;
981 metadata_x *metadata = NULL;
982 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
984 list_md = info->app_info->metadata;
986 for (; list_md; list_md = list_md->next) {
987 metadata = (metadata_x *)list_md->data;
988 if (metadata && metadata->key) {
989 if (strcasecmp(metadata->key, metadata_key) == 0) {
990 if (metadata->value == NULL)
991 *metadata_value = "";
993 *metadata_value = (char *)metadata->value;
999 return PMINFO_R_EINVAL;
1002 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1004 if (strcasecmp(comp, "uiapp") == 0)
1005 return PMINFO_UI_APP;
1006 else if (strcasecmp(comp, "svcapp") == 0)
1007 return PMINFO_SVC_APP;
1008 else if (strcasecmp(comp, "widgetapp") == 0)
1009 return PMINFO_WIDGET_APP;
1010 else if (strcasecmp(comp, "watchapp") == 0)
1011 return PMINFO_WATCH_APP;
1012 else if (strcasecmp(comp, "componentbasedapp") == 0)
1013 return PMINFO_COMPONENT_BASED_APP;
1018 static const char *__appcomponent_str(pkgmgrinfo_app_component comp)
1023 case PMINFO_SVC_APP:
1025 case PMINFO_WIDGET_APP:
1027 case PMINFO_WATCH_APP:
1029 case PMINFO_COMPONENT_BASED_APP:
1030 return "componentbasedapp";
1036 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1038 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1041 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1042 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1044 if (info->app_info == NULL)
1045 return PMINFO_R_ERROR;
1047 comp = __appcomponent_convert(info->app_info->component);
1049 return PMINFO_R_ERROR;
1056 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1058 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1060 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1061 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1063 if (info->app_info == NULL || info->app_info->type == NULL)
1064 return PMINFO_R_ERROR;
1065 *app_type = (char *)info->app_info->type;
1070 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1075 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1077 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1078 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1080 if (info->app_info == NULL)
1081 return PMINFO_R_ERROR;
1083 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1084 ptr = (icon_x *)tmp->data;
1085 if (ptr == NULL || ptr->section == NULL)
1088 val = (char *)ptr->section;
1089 if (val && strcmp(val, "notification") == 0) {
1090 *icon = (char *)ptr->text;
1095 return PMINFO_R_ERROR;
1098 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1101 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1103 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1104 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1106 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1107 return PMINFO_R_ERROR;
1109 val = (char *)info->app_info->recentimage;
1110 if (strcasecmp(val, "capture") == 0)
1111 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1112 else if (strcasecmp(val, "icon") == 0)
1113 *type = PMINFO_RECENTIMAGE_USE_ICON;
1115 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1120 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1125 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1127 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1128 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1130 if (info->app_info == NULL)
1131 return PMINFO_R_ERROR;
1133 for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1134 ptr = (image_x *)tmp->data;
1135 if (ptr == NULL || ptr->section == NULL)
1138 val = (char *)ptr->section;
1139 if (val && strcmp(val, "preview") == 0) {
1140 *preview_img = (char *)ptr->text;
1145 return PMINFO_R_ERROR;
1148 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1151 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1153 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1154 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1156 val = info->app_info->permission_type;
1158 return PMINFO_R_ERROR;
1160 if (strcmp(val, "signature") == 0)
1161 *permission = PMINFO_PERMISSION_SIGNATURE;
1162 else if (strcmp(val, "privilege") == 0)
1163 *permission = PMINFO_PERMISSION_PRIVILEGE;
1165 *permission = PMINFO_PERMISSION_NORMAL;
1170 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1172 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1174 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1175 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1177 if (info->app_info == NULL || info->app_info->component_type == NULL)
1178 return PMINFO_R_ERROR;
1180 *component_type = (char *)info->app_info->component_type;
1185 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1188 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1190 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1191 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1193 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1194 return PMINFO_R_ERROR;
1196 val = (char *)info->app_info->hwacceleration;
1197 if (strcasecmp(val, "off") == 0)
1198 *hwacceleration = PMINFO_HWACCELERATION_OFF;
1199 else if (strcasecmp(val, "on") == 0)
1200 *hwacceleration = PMINFO_HWACCELERATION_ON;
1202 *hwacceleration = PMINFO_HWACCELERATION_DEFAULT;
1207 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1210 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1212 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1213 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1215 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1216 return PMINFO_R_ERROR;
1218 val = (char *)info->app_info->screenreader;
1219 if (strcasecmp(val, "screenreader-off") == 0)
1220 *screenreader = PMINFO_SCREENREADER_OFF;
1221 else if (strcasecmp(val, "screenreader-on") == 0)
1222 *screenreader = PMINFO_SCREENREADER_ON;
1224 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1229 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1231 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1233 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1234 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1235 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1237 if (info->app_info == NULL)
1238 return PMINFO_R_ERROR;
1240 if (info->app_info->portraitimg == NULL)
1243 *portrait_img = (char *)info->app_info->portraitimg;
1245 if (info->app_info->landscapeimg == NULL)
1246 *landscape_img = "";
1248 *landscape_img = (char *)info->app_info->landscapeimg;
1253 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
1255 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1257 if (handle == NULL || effectimage_type == NULL) {
1258 LOGE("invalid parameter");
1259 return PMINFO_R_EINVAL;
1262 if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
1263 return PMINFO_R_ERROR;
1265 *effectimage_type = (char *)info->app_info->effectimage_type;
1270 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
1272 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1274 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1275 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1277 if (info->app_info == NULL)
1278 return PMINFO_R_ERROR;
1280 if (info->app_info->submode_mainid == NULL)
1281 *submode_mainid = "";
1283 *submode_mainid = (char *)info->app_info->submode_mainid;
1288 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
1290 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1291 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1293 if (info->app_info && info->app_info->installed_storage) {
1294 if (strcmp(info->app_info->installed_storage, "installed_internal") == 0)
1295 *storage = PMINFO_INTERNAL_STORAGE;
1296 else if (strcmp(info->app_info->installed_storage, "installed_external") == 0)
1297 *storage = PMINFO_EXTERNAL_STORAGE;
1299 return PMINFO_R_ERROR;
1301 return PMINFO_R_ERROR;
1307 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
1309 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1311 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1312 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1314 if (info->app_info->launch_mode == NULL)
1315 return PMINFO_R_ERROR;
1317 *mode = (char *)(info->app_info->launch_mode);
1322 API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
1324 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1326 if (handle == NULL || alias_appid == NULL) {
1327 LOGE("invalid parameter");
1328 return PMINFO_R_EINVAL;
1331 if (info->app_info == NULL || info->app_info->alias_appid == NULL)
1332 return PMINFO_R_ERROR;
1334 *alias_appid = (char *)info->app_info->alias_appid;
1339 API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
1341 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1343 if (handle == NULL || effective_appid == NULL) {
1344 LOGE("invalid parameter");
1345 return PMINFO_R_EINVAL;
1348 if (info->app_info == NULL)
1349 return PMINFO_R_ERROR;
1351 if (info->app_info->effective_appid == NULL)
1352 *effective_appid = "";
1354 *effective_appid = (char *)info->app_info->effective_appid;
1359 API int pkgmgrinfo_appinfo_get_tep_name(pkgmgrinfo_appinfo_h handle, char **tep_name)
1361 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1363 if (handle == NULL || tep_name == NULL) {
1364 LOGE("invalid parameter");
1365 return PMINFO_R_EINVAL;
1368 if (info->app_info == NULL)
1369 return PMINFO_R_ERROR;
1371 if (info->app_info->tep_name == NULL)
1374 *tep_name = (char *)info->app_info->tep_name;
1379 API int pkgmgrinfo_appinfo_get_zip_mount_file(pkgmgrinfo_appinfo_h handle, char **zip_mount_file)
1381 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1383 if (handle == NULL || zip_mount_file == NULL) {
1384 LOGE("invalid parameter");
1385 return PMINFO_R_EINVAL;
1388 if (info->app_info == NULL)
1389 return PMINFO_R_ERROR;
1391 if (info->app_info->zip_mount_file == NULL)
1392 *zip_mount_file = "";
1394 *zip_mount_file = (char *)info->app_info->zip_mount_file;
1399 API int pkgmgrinfo_appinfo_get_root_path(pkgmgrinfo_appinfo_h handle, char **root_path)
1401 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1403 if (handle == NULL || root_path == NULL) {
1404 LOGE("invalid parameter");
1405 return PMINFO_R_EINVAL;
1408 if (info->app_info == NULL || info->app_info->root_path == NULL)
1409 return PMINFO_R_ERROR;
1411 *root_path = (char *)info->app_info->root_path;
1416 API int pkgmgrinfo_appinfo_get_api_version(pkgmgrinfo_appinfo_h handle, char **api_version)
1418 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1420 if (handle == NULL || api_version == NULL) {
1421 LOGE("invalid parameter");
1422 return PMINFO_R_EINVAL;
1425 if (info->app_info == NULL || info->app_info->api_version == NULL)
1426 return PMINFO_R_ERROR;
1428 *api_version = (char *)info->app_info->api_version;
1433 API int pkgmgrinfo_appinfo_get_installed_time(pkgmgrinfo_appinfo_h handle, int *installed_time)
1435 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1437 if (handle == NULL || installed_time == NULL) {
1438 LOGE("invalid parameter");
1439 return PMINFO_R_EINVAL;
1442 if (info->app_info == NULL || info->app_info->package_installed_time == NULL)
1443 return PMINFO_R_ERROR;
1445 *installed_time = atoi(info->app_info->package_installed_time);
1450 static int _appinfo_get_datacontrol_info(const char *providerid,
1451 const char *type, char **appid, char **access)
1456 query = sqlite3_mprintf("SELECT app_id, access FROM package_app_data_control "
1457 "WHERE providerid=%Q AND type=%Q", providerid, type);
1458 if (query == NULL) {
1459 LOGE("Out of memory");
1460 return PMINFO_R_ERROR;
1463 // TODO: need to use pkginfo-client APIs
1464 sqlite3_free(query);
1468 static int _pkgmgrinfo_appinfo_get_datacontrol_info(uid_t uid,
1469 const char *providerid, const char *type,
1470 char **appid, char **access)
1474 ret = _appinfo_get_datacontrol_info(providerid, type, appid,
1480 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid,
1481 const char *type, uid_t uid, char **appid, char **access)
1485 if (providerid == NULL || type == NULL || appid == NULL ||
1487 LOGE("invalid parameter");
1488 return PMINFO_R_EINVAL;
1491 ret = _pkgmgrinfo_appinfo_get_datacontrol_info(GLOBAL_USER, providerid,
1492 type, appid, access);
1493 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
1494 ret = _pkgmgrinfo_appinfo_get_datacontrol_info(uid, providerid,
1495 type, appid, access);
1497 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
1498 * implementation, return PMINFO_R_ERROR. This should be
1501 if (ret == PMINFO_R_ENOENT) {
1502 LOGE("no datacontrol info of %s", providerid);
1503 ret = PMINFO_R_ERROR;
1509 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid,
1510 const char *type, char **appid, char **access)
1512 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid,
1513 type, _getuid(), appid, access);
1516 static int _appinfo_get_datacontrol_appid(const char *providerid,
1521 query = sqlite3_mprintf("SELECT app_id FROM package_app_data_control "
1522 "WHERE providerid=%Q", providerid);
1523 if (query == NULL) {
1524 LOGE("Out of memory");
1525 return PMINFO_R_ERROR;
1528 // TODO: change to use pkginfo-client APIs
1529 sqlite3_free(query);
1533 static int _pkgmgrinfo_appinfo_get_datacontrol_appid(uid_t uid,
1534 const char *providerid, char **appid)
1538 ret = _appinfo_get_datacontrol_appid(providerid, appid);
1542 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid,
1543 uid_t uid, char **appid)
1547 if (providerid == NULL || appid == NULL) {
1548 LOGE("invalid parameter");
1549 return PMINFO_R_EINVAL;
1552 ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(GLOBAL_USER, providerid,
1554 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
1555 ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(uid, providerid,
1558 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
1559 * implementation, return PMINFO_R_ERROR. This should be
1562 if (ret == PMINFO_R_ENOENT) {
1563 LOGE("no datacontrol appid of %s", providerid);
1564 ret = PMINFO_R_ERROR;
1570 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1572 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid);
1575 static int _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid_t uid,
1576 const char *providerid, const char *type, char **appid,
1581 query = sqlite3_mprintf(
1582 "SELECT app_id, trusted FROM package_app_data_control "
1583 "WHERE providerid=%Q AND type=%Q", providerid, type);
1587 // TODO: need to use pkginfo-client APIs
1588 sqlite3_free(query);
1592 API int pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(
1593 const char *providerid, const char *type, uid_t uid,
1594 char **appid, bool *is_trusted)
1598 if (providerid == NULL || type == NULL || appid == NULL ||
1599 is_trusted == NULL) {
1600 LOGE("invalid parameter");
1601 return PMINFO_R_EINVAL;
1604 ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(GLOBAL_USER,
1605 providerid, type, appid, is_trusted);
1606 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
1607 ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid,
1608 providerid, type, appid, is_trusted);
1610 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
1611 * implementation, return PMINFO_R_ERROR. This should be
1614 if (ret == PMINFO_R_ENOENT) {
1615 LOGE("no datacontrol trusted info of %s", providerid);
1616 ret = PMINFO_R_ERROR;
1622 API int pkgmgrinfo_appinfo_get_datacontrol_trsuted_info(const char *providerid,
1623 const char *type, char **appid, bool *is_trusted)
1625 return pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(providerid,
1626 type, _getuid(), appid, is_trusted);
1629 static int _appinfo_foreach_datacontrol_privileges(
1630 const char *providerid, const char *type,
1631 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
1635 query = sqlite3_mprintf(
1636 "SELECT privilege FROM package_app_data_control_privilege "
1637 "WHERE providerid=%Q AND type=%Q", providerid, type);
1638 if (query == NULL) {
1639 LOGE("Out of memory");
1640 return PMINFO_R_ERROR;
1643 // TODO: need to change to use pkginfo-client APIs
1644 sqlite3_free(query);
1648 static int _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid_t uid,
1649 const char *providerid, const char *type,
1650 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
1654 ret = _appinfo_foreach_datacontrol_privileges(providerid, type,
1655 callback, user_data);
1660 API int pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
1661 const char *providerid, const char *type,
1662 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
1663 void *user_data, uid_t uid)
1667 if (providerid == NULL || type == NULL || privilege_func == NULL) {
1668 LOGE("invalid parameter");
1669 return PMINFO_R_EINVAL;
1672 ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(GLOBAL_USER,
1673 providerid, type, privilege_func, user_data);
1674 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
1675 ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid,
1676 providerid, type, privilege_func, user_data);
1678 if (ret == PMINFO_R_ENOENT)
1684 API int pkgmgrinfo_appinfo_foreach_datacontrol_privileges(
1685 const char *providerid, const char *type,
1686 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
1689 return pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
1690 providerid, type, privilege_func, user_data, _getuid());
1693 API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h handle, int *support_mode)
1695 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1696 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1698 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1699 if (info->app_info->support_mode)
1700 *support_mode = atoi(info->app_info->support_mode);
1707 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
1708 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
1710 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1711 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1713 const char *category;
1715 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1717 if (info->app_info == NULL)
1718 return PMINFO_R_ERROR;
1720 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
1721 category = (const char *)tmp->data;
1723 ret = category_func(category, user_data);
1731 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
1732 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
1734 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1735 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1739 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1741 if (info->app_info == NULL)
1742 return PMINFO_R_ERROR;
1744 for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
1745 ptr = (metadata_x *)tmp->data;
1749 ret = metadata_func(ptr->key, ptr->value ? ptr->value : "", user_data);
1757 static int _appinfo_foreach_appcontrol_privileges(
1758 const char *appid, const char *operation,
1759 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
1763 query = sqlite3_mprintf(
1764 "SELECT app_control, privilege FROM package_app_app_control_privilege "
1765 "WHERE app_id=%Q", appid);
1766 if (query == NULL) {
1767 LOGE("Out of memory");
1768 return PMINFO_R_ERROR;
1771 // TODO: need to remove this codes and change to use pkginfo-client APIs
1772 sqlite3_free(query);
1776 static int _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid_t uid,
1777 const char *appid, const char *operation,
1778 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
1782 ret = _appinfo_foreach_appcontrol_privileges(appid, operation,
1783 callback, user_data);
1788 API int pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(const char *appid,
1789 const char *operation,
1790 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
1791 void *user_data, uid_t uid)
1795 if (appid == NULL || operation == NULL || privilege_func == NULL) {
1796 LOGE("invalid parameter");
1797 return PMINFO_R_EINVAL;
1800 ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(GLOBAL_USER,
1801 appid, operation, privilege_func, user_data);
1802 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
1803 ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid,
1804 appid, operation, privilege_func, user_data);
1806 if (ret == PMINFO_R_ENOENT)
1812 API int pkgmgrinfo_appinfo_foreach_appcontrol_privileges(const char *appid,
1813 const char *operation,
1814 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
1817 return pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(appid,
1818 operation, privilege_func, user_data, _getuid());
1821 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
1822 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1824 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1825 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1827 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1828 appcontrol_x *appcontrol;
1831 if (info->app_info == NULL)
1832 return PMINFO_R_ERROR;
1834 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
1835 appcontrol = (appcontrol_x *)tmp->data;
1836 if (appcontrol == NULL || !strcasecmp(appcontrol->visibility, "remote-only"))
1838 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1846 API int pkgmgrinfo_appinfo_foreach_remote_appcontrol(pkgmgrinfo_appinfo_h handle,
1847 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1849 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1850 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1852 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1853 appcontrol_x *appcontrol;
1856 if (info->app_info == NULL)
1857 return PMINFO_R_ERROR;
1859 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
1860 appcontrol = (appcontrol_x *)tmp->data;
1861 if (appcontrol == NULL || !strcasecmp(appcontrol->visibility, "local-only"))
1863 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1871 API int pkgmgrinfo_appinfo_foreach_background_category(
1872 pkgmgrinfo_appinfo_h handle,
1873 pkgmgrinfo_app_background_category_list_cb category_func,
1876 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1880 if (handle == NULL || category_func == NULL || info->app_info == NULL) {
1881 LOGE("invalid parameter");
1882 return PMINFO_R_EINVAL;
1885 for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
1886 category = (char *)tmp->data;
1887 if (category == NULL)
1890 if (category_func(category, user_data) < 0)
1897 API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
1898 pkgmgrinfo_app_splash_screen_list_cb splash_screen_func,
1901 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1902 splashscreen_x *splashscreen;
1906 if (info == NULL || info->app_info == NULL
1907 || splash_screen_func == NULL) {
1908 LOGE("invalid parameter");
1909 return PMINFO_R_EINVAL;
1912 for (tmp = info->app_info->splashscreens; tmp; tmp = tmp->next) {
1913 splashscreen = (splashscreen_x *)tmp->data;
1914 if (splashscreen == NULL)
1916 ret = splash_screen_func(splashscreen->src,
1918 splashscreen->orientation,
1919 splashscreen->indicatordisplay,
1920 splashscreen->operation,
1921 splashscreen->color_depth,
1930 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
1932 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1933 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1934 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1936 if (info->app_info == NULL || info->app_info->nodisplay == NULL)
1937 return PMINFO_R_ERROR;
1939 *nodisplay = _get_bool_value(info->app_info->nodisplay);
1944 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
1946 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1947 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1948 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1950 if (info->app_info == NULL || info->app_info->multiple == NULL)
1951 return PMINFO_R_ERROR;
1953 *multiple = _get_bool_value(info->app_info->multiple);
1958 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
1960 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1961 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1962 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1964 if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
1965 return PMINFO_R_ERROR;
1967 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
1972 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
1974 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1975 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1976 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1978 if (info->app_info == NULL || info->app_info->taskmanage == NULL)
1979 return PMINFO_R_ERROR;
1981 *taskmanage = _get_bool_value(info->app_info->taskmanage);
1986 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
1988 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1989 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1990 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1992 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
1993 return PMINFO_R_ERROR;
1995 *enabled = !_get_bool_value(info->app_info->is_disabled);
2000 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
2002 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2003 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2004 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2006 if (info->app_info == NULL || info->app_info->onboot == NULL)
2007 return PMINFO_R_ERROR;
2009 *onboot = _get_bool_value(info->app_info->onboot);
2014 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
2016 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2017 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2018 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2020 if (info->app_info == NULL || info->app_info->autorestart == NULL)
2021 return PMINFO_R_ERROR;
2023 *autorestart = _get_bool_value(info->app_info->autorestart);
2028 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
2030 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2031 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2032 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2034 if (info->app_info == NULL || info->app_info->mainapp == NULL)
2035 return PMINFO_R_ERROR;
2037 *mainapp = _get_bool_value(info->app_info->mainapp);
2042 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
2044 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2045 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2046 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2048 if (info->app_info == NULL || info->app_info->preload == NULL)
2049 return PMINFO_R_ERROR;
2051 *preload = _get_bool_value(info->app_info->preload);
2056 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
2058 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2059 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2060 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2062 if (info->app_info == NULL || info->app_info->submode == NULL)
2063 return PMINFO_R_ERROR;
2065 *submode = _get_bool_value(info->app_info->submode);
2070 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
2072 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2074 if (handle == NULL || process_pool == NULL) {
2075 LOGE("invalid parameter");
2076 return PMINFO_R_EINVAL;
2079 if (info->app_info == NULL)
2080 return PMINFO_R_ERROR;
2082 *process_pool = _get_bool_value(info->app_info->process_pool);
2087 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
2089 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2090 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
2091 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
2095 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2097 if (info->app_info == NULL)
2098 return PMINFO_R_ERROR;
2101 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2102 val = (const char *)tmp->data;
2105 if (strcasecmp(val, category) == 0) {
2114 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
2117 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2119 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
2120 _LOGE("invalid parameter");
2121 return PMINFO_R_EINVAL;
2123 if (info->app_info->ui_gadget == NULL)
2124 info->app_info->ui_gadget = strdup("false");
2126 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
2131 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
2132 bool *support_disable)
2134 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2136 if (info == NULL || info->app_info == NULL || support_disable == NULL) {
2137 _LOGE("invalid parameter");
2138 return PMINFO_R_EINVAL;
2141 *support_disable = _get_bool_value(info->app_info->support_disable);
2146 API int pkgmgrinfo_appinfo_is_removable(pkgmgrinfo_appinfo_h handle,
2149 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2151 if (info == NULL || info->app_info == NULL || removable == NULL) {
2152 _LOGE("invalid parameter");
2153 return PMINFO_R_EINVAL;
2156 *removable = _get_bool_value(info->app_info->removable);
2161 API int pkgmgrinfo_appinfo_is_system(pkgmgrinfo_appinfo_h handle, bool *system)
2163 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2165 if (info == NULL || info->app_info == NULL || system == NULL) {
2166 _LOGE("invalid parameter");
2167 return PMINFO_R_EINVAL;
2170 *system = _get_bool_value(info->app_info->package_system);
2175 API int pkgmgrinfo_appinfo_is_disabled(pkgmgrinfo_appinfo_h handle, bool *disabled)
2177 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2178 retvm_if(disabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2179 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2181 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
2182 return PMINFO_R_ERROR;
2184 *disabled = _get_bool_value(info->app_info->is_disabled);
2189 API int pkgmgrinfo_appinfo_is_global(pkgmgrinfo_appinfo_h handle, bool *global)
2191 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2193 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2194 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2196 if (info->app_info == NULL || info->app_info->for_all_users == NULL)
2197 return PMINFO_R_ERROR;
2199 *global = _get_bool_value(info->app_info->for_all_users);
2204 API int pkgmgrinfo_appinfo_get_splash_screen_display(pkgmgrinfo_appinfo_h handle, bool *splash_screen_display)
2206 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2208 if (info == NULL || splash_screen_display == NULL) {
2209 _LOGE("Invalid parameter");
2210 return PMINFO_R_EINVAL;
2213 if (info->app_info == NULL || info->app_info->splash_screen_display == NULL)
2214 return PMINFO_R_ERROR;
2216 *splash_screen_display = _get_bool_value(info->app_info->splash_screen_display);
2221 API int pkgmgrinfo_appinfo_get_setup_appid(pkgmgrinfo_appinfo_h handle, char **setup_appid)
2223 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2225 if (info == NULL || setup_appid == NULL) {
2226 _LOGE("Invalid parameter");
2227 return PMINFO_R_EINVAL;
2230 if (info->app_info == NULL || info->app_info->setup_appid == NULL)
2231 return PMINFO_R_ERROR;
2233 *setup_appid = info->app_info->setup_appid;
2237 API int pkgmgrinfo_appinfo_is_support_ambient(pkgmgrinfo_appinfo_h handle,
2238 bool *support_ambient)
2240 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2242 if (info == NULL || support_ambient == NULL) {
2243 _LOGE("Invalid parameter");
2244 return PMINFO_R_EINVAL;
2247 if (info->app_info == NULL || info->app_info->support_ambient == NULL)
2248 return PMINFO_R_ERROR;
2250 *support_ambient = _get_bool_value(info->app_info->support_ambient);
2255 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
2257 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2258 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2259 __cleanup_appinfo(info);
2263 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
2265 return (pkgmgrinfo_pkginfo_filter_create(handle));
2268 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
2270 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2273 static gint __compare_func(gconstpointer data1, gconstpointer data2)
2275 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
2276 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
2277 if (node1->prop == node2->prop)
2279 else if (node1->prop > node2->prop)
2285 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
2286 const char *property, const int value)
2288 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2289 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2290 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
2292 GSList *link = NULL;
2294 prop = _pminfo_appinfo_convert_to_prop_int(property);
2295 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
2296 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
2297 _LOGE("Invalid Integer Property\n");
2298 return PMINFO_R_EINVAL;
2300 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2301 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
2303 _LOGE("Out of Memory!!!\n");
2304 return PMINFO_R_ERROR;
2306 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
2307 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
2309 _LOGE("Out of Memory\n");
2312 return PMINFO_R_ERROR;
2316 /*If API is called multiple times for same property, we should override the previous values.
2317 Last value set will be used for filtering.*/
2318 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2320 filter->list = g_slist_delete_link(filter->list, link);
2321 filter->list = g_slist_append(filter->list, (gpointer)node);
2326 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
2327 const char *property, const bool value)
2329 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2330 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2332 GSList *link = NULL;
2334 prop = _pminfo_appinfo_convert_to_prop_bool(property);
2335 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
2336 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
2337 _LOGE("Invalid Boolean Property\n");
2338 return PMINFO_R_EINVAL;
2340 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2341 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
2343 _LOGE("Out of Memory!!!\n");
2344 return PMINFO_R_ERROR;
2347 val = strndup("true", 4);
2349 val = strndup("false", 5);
2351 _LOGE("Out of Memory\n");
2354 return PMINFO_R_ERROR;
2358 /*If API is called multiple times for same property, we should override the previous values.
2359 Last value set will be used for filtering.*/
2360 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2362 filter->list = g_slist_delete_link(filter->list, link);
2363 filter->list = g_slist_append(filter->list, (gpointer)node);
2368 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
2369 const char *property, const char *value)
2371 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2372 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2373 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2375 pkgmgrinfo_node_x *ptr = NULL;
2376 char prev[PKG_STRING_LEN_MAX] = {'\0'};
2377 char temp[PKG_STRING_LEN_MAX] = {'\0'};
2378 GSList *link = NULL;
2381 prop = _pminfo_appinfo_convert_to_prop_str(property);
2382 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
2383 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
2384 _LOGE("Invalid String Property\n");
2385 return PMINFO_R_EINVAL;
2387 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2388 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
2390 _LOGE("Out of Memory!!!\n");
2391 return PMINFO_R_ERROR;
2395 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
2396 node->value = strdup(value);
2397 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2399 filter->list = g_slist_delete_link(filter->list, link);
2400 filter->list = g_slist_append(filter->list, (gpointer)node);
2402 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
2403 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
2405 _LOGE("Out of Memory\n");
2408 return PMINFO_R_ERROR;
2410 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2412 ptr = (pkgmgrinfo_node_x *)link->data;
2413 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
2414 _LOGI("Previous value is %s\n", prev);
2415 filter->list = g_slist_delete_link(filter->list, link);
2416 ret = snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s,%s", prev, value);
2417 if (ret < 0 || ret > PKG_STRING_LEN_MAX - 1) {
2418 _LOGE("snprintf fail\n");
2421 return PMINFO_R_ERROR;
2423 strncpy(val, temp, PKG_STRING_LEN_MAX);
2424 _LOGI("New value is %s\n", val);
2426 filter->list = g_slist_append(filter->list, (gpointer)node);
2427 memset(temp, '\0', PKG_STRING_LEN_MAX);
2429 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s", value);
2430 strncpy(val, temp, PKG_STRING_LEN_MAX);
2431 _LOGI("First value is %s\n", val);
2433 filter->list = g_slist_append(filter->list, (gpointer)node);
2434 memset(temp, '\0', PKG_STRING_LEN_MAX);
2438 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
2439 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2441 filter->list = g_slist_delete_link(filter->list, link);
2442 filter->list = g_slist_append(filter->list, (gpointer)node);
2448 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
2452 if (handle == NULL || count == NULL) {
2453 _LOGE("invalid parameter");
2454 return PMINFO_R_EINVAL;
2457 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
2458 __free_applications);
2460 return PMINFO_R_ERROR;
2462 if (__check_disable_filter_exist(
2463 handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
2464 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
2465 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
2466 g_hash_table_destroy(list);
2467 return PMINFO_R_ERROR;
2471 if (__check_disable_filter_exist(
2472 handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
2473 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
2474 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
2475 g_hash_table_destroy(list);
2476 return PMINFO_R_ERROR;
2480 // TODO: use pkginfo-client APIs
2481 *count = g_hash_table_size(list);
2482 g_hash_table_destroy(list);
2487 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
2489 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, _getuid());
2492 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
2493 pkgmgrinfo_appinfo_filter_h handle,
2494 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2496 if (handle == NULL || app_cb == NULL) {
2497 LOGE("invalid parameter");
2498 return PMINFO_R_EINVAL;
2501 if (__check_disable_filter_exist(
2502 handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
2503 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
2504 PMINFO_APPINFO_PROP_APP_DISABLE, false))
2505 return PMINFO_R_ERROR;
2508 if (__check_disable_filter_exist(
2509 handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
2510 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
2511 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
2512 return PMINFO_R_ERROR;
2515 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
2519 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
2520 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2522 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, _getuid());
2525 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
2527 return (pkgmgrinfo_pkginfo_filter_create(handle));
2530 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
2532 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2535 API int pkgmgrinfo_appinfo_metadata_filter_add(
2536 pkgmgrinfo_appinfo_metadata_filter_h handle,
2537 const char *key, const char *value)
2539 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2540 pkgmgrinfo_metadata_node_x *node;
2542 /* value can be NULL.
2543 * In that case all apps with specified key should be displayed
2546 LOGE("invalid parameter");
2547 return PMINFO_R_EINVAL;
2550 node = calloc(1, sizeof(pkgmgrinfo_metadata_node_x));
2552 LOGE("out of memory");
2553 return PMINFO_R_ERROR;
2556 node->key = strdup(key);
2557 if (value && strlen(value))
2558 node->value = strdup(value);
2560 filter->list_metadata = g_slist_append(filter->list_metadata,
2566 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2567 pkgmgrinfo_appinfo_metadata_filter_h handle,
2568 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2570 if (handle == NULL || app_cb == NULL) {
2571 LOGE("invalid parameter");
2572 return PMINFO_R_EINVAL;
2575 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2576 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
2577 PMINFO_APPINFO_PROP_APP_DISABLE, false))
2578 return PMINFO_R_ERROR;
2580 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
2581 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
2582 return PMINFO_R_ERROR;
2584 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
2588 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
2589 pkgmgrinfo_appinfo_metadata_filter_h handle,
2590 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2592 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
2593 user_data, _getuid());
2596 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2599 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2601 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2602 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2604 val = info->app_info->guestmode_visibility;
2605 *status = _get_bool_value(val);
2609 API int pkgmgrinfo_appinfo_foreach_appcontrol_v2(pkgmgrinfo_appinfo_h handle,
2610 pkgmgrinfo_app_control_list_cb_v2 appcontrol_func,
2613 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2614 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2616 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2617 appcontrol_x *appcontrol;
2620 if (info->app_info == NULL)
2621 return PMINFO_R_ERROR;
2623 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2624 appcontrol = (appcontrol_x *)tmp->data;
2625 if (appcontrol == NULL ||
2626 !strcasecmp(appcontrol->visibility, "remote-only"))
2628 ret = appcontrol_func(appcontrol->operation, appcontrol->uri,
2629 appcontrol->mime, appcontrol->id, user_data);
2637 API int pkgmgrinfo_appinfo_foreach_remote_appcontrol_v2(
2638 pkgmgrinfo_appinfo_h handle,
2639 pkgmgrinfo_app_control_list_cb_v2 appcontrol_func,
2642 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2643 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2645 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2646 appcontrol_x *appcontrol;
2649 if (info->app_info == NULL)
2650 return PMINFO_R_ERROR;
2652 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2653 appcontrol = (appcontrol_x *)tmp->data;
2654 if (appcontrol == NULL ||
2655 !strcasecmp(appcontrol->visibility, "local-only"))
2657 ret = appcontrol_func(appcontrol->operation, appcontrol->uri,
2658 appcontrol->mime, appcontrol->id, user_data);