2 * Copyright (c) 2011 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
25 #include <pkgmgr-info.h>
26 #include <package-manager.h>
28 #include <cynara-client.h>
33 #include "app_manager.h"
34 #include "app_manager_internal.h"
40 #define LOG_TAG "TIZEN_N_APP_MANAGER"
42 #define SMACK_LABEL_LEN 255
44 #undef REGULAR_UID_MIN
45 #define REGULAR_UID_MIN 5000
49 pkgmgrinfo_appinfo_h pkg_app_info;
52 struct app_info_filter_s {
53 pkgmgrinfo_appinfo_filter_h pkg_app_info_filter;
56 struct app_info_metadata_filter_s {
57 pkgmgrinfo_appinfo_metadata_filter_h pkg_app_info_metadata_filter;
60 typedef struct _foreach_context_ {
61 app_manager_app_info_cb callback;
65 typedef struct _foreach_metada_context_ {
66 app_info_metadata_cb callback;
68 } foreach_metadata_context_s;
70 typedef struct _foreach_category_ {
71 app_info_category_cb callback;
73 } foreach_category_context_s;
75 typedef struct _foreach_res_control_ {
76 app_info_res_control_cb callback;
78 } foreach_res_control_context_s;
80 typedef struct app_context_s {
85 static app_context_t __context;
86 static pthread_mutex_t __mutex = PTHREAD_MUTEX_INITIALIZER;
88 static int app_info_convert_str_property(const char *property, char **converted_property)
93 if (strcmp(property, PACKAGE_INFO_PROP_APP_ID) == 0)
94 *converted_property = PMINFO_APPINFO_PROP_APP_ID;
95 else if (strcmp(property, PACKAGE_INFO_PROP_APP_TYPE) == 0)
96 *converted_property = PMINFO_APPINFO_PROP_APP_TYPE;
97 else if (strcmp(property, PACKAGE_INFO_PROP_APP_CATEGORY) == 0)
98 *converted_property = PMINFO_APPINFO_PROP_APP_CATEGORY;
99 else if (strcmp(property, PACKAGE_INFO_PROP_APP_INSTALLED_STORAGE) == 0)
100 *converted_property = PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE;
101 else if (strcmp(property, PACKAGE_INFO_PROP_APP_COMPONENT_TYPE) == 0)
102 *converted_property = PMINFO_APPINFO_PROP_APP_COMPONENT;
109 static int app_info_convert_bool_property(const char *property, char **converted_property)
111 if (property == NULL)
114 if (strcmp(property, PACKAGE_INFO_PROP_APP_NODISPLAY) == 0)
115 *converted_property = PMINFO_APPINFO_PROP_APP_NODISPLAY;
116 else if (strcmp(property, PACKAGE_INFO_PROP_APP_TASKMANAGE) == 0)
117 *converted_property = PMINFO_APPINFO_PROP_APP_TASKMANAGE;
118 else if (strcmp(property, PACKAGE_INFO_PROP_APP_DISABLED) == 0)
119 *converted_property = PMINFO_APPINFO_PROP_APP_DISABLE;
126 static int app_info_convert_app_component(pkgmgrinfo_app_component component, app_info_app_component_type_e *converted_component)
128 if (component == PMINFO_UI_APP)
129 *converted_component = APP_INFO_APP_COMPONENT_TYPE_UI_APP;
130 else if (component == PMINFO_SVC_APP)
131 *converted_component = APP_INFO_APP_COMPONENT_TYPE_SERVICE_APP;
132 else if (component == PMINFO_WIDGET_APP)
133 *converted_component = APP_INFO_APP_COMPONENT_TYPE_WIDGET_APP;
134 else if (component == PMINFO_WATCH_APP)
135 *converted_component = APP_INFO_APP_COMPONENT_TYPE_WATCH_APP;
136 else if (component == PMINFO_COMPONENT_BASED_APP)
137 *converted_component = APP_INFO_APP_COMPONENT_TYPE_COMPONENT_BASED_APP;
144 static int app_info_foreach_app_filter_cb(pkgmgrinfo_appinfo_h handle, void *user_data)
148 app_info_h info = NULL;
149 bool iteration_next = true;
151 info = calloc(1, sizeof(struct app_info_s));
153 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
155 foreach_context_s *foreach_context = user_data;
156 if (handle == NULL || foreach_context == NULL) {
157 /* LCOV_EXCL_START */
159 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
163 retval = pkgmgrinfo_appinfo_get_appid(handle, &appid);
165 /* LCOV_EXCL_START */
167 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
171 info->app_id = strdup(appid);
172 if (info->app_id == NULL) {
173 /* LCOV_EXCL_START */
178 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
181 info->pkg_app_info = handle;
183 iteration_next = foreach_context->callback(info, foreach_context->user_data);
188 if (iteration_next == true)
191 return PMINFO_R_ERROR;
194 static int app_info_foreach_app_metadata_cb(const char *metadata_key, const char *metadata_value, void *user_data)
196 foreach_metadata_context_s *foreach_context = user_data;
197 bool iteration_next = true;
199 if (metadata_value == NULL || foreach_context == NULL)
200 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
202 iteration_next = foreach_context->callback(metadata_key, metadata_value, foreach_context->user_data);
203 if (iteration_next == true)
206 return PMINFO_R_ERROR;
209 static int app_info_foreach_category_cb(const char *category_name, void *user_data)
211 foreach_category_context_s *foreach_category = user_data;
212 bool iteration_next = true;
214 if (category_name == NULL || foreach_category == NULL)
215 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
217 iteration_next = foreach_category->callback(category_name, foreach_category->user_data);
218 if (iteration_next == true)
221 return PMINFO_R_ERROR;
224 static int app_info_foreach_app_info_cb(pkgmgrinfo_appinfo_h handle, void *cb_data)
226 foreach_context_s *foreach_context = cb_data;
227 app_info_h app_info = NULL;
230 bool iteration_next = true;
232 if (handle == NULL || foreach_context == NULL) {
233 app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
234 return PMINFO_R_ERROR;
237 ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
238 if (ret != PMINFO_R_OK) {
239 /* LCOV_EXCL_START */
240 app_manager_error(APP_MANAGER_ERROR_NO_SUCH_APP, __FUNCTION__, NULL);
241 return PMINFO_R_ERROR;
245 app_info = calloc(1, sizeof(struct app_info_s));
246 if (app_info == NULL) {
247 /* LCOV_EXCL_START */
248 app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
249 return PMINFO_R_ERROR;
253 app_info->app_id = strdup(appid);
254 app_info->pkg_app_info = handle;
255 iteration_next = foreach_context->callback(app_info, foreach_context->user_data);
257 free(app_info->app_id);
260 if (iteration_next == true)
263 return PMINFO_R_ERROR;
266 static int app_info_foreach_res_control_cb(const char *res_type,
267 const char *min_res_version, const char *max_res_version,
268 const char *auto_close, void *user_data)
270 foreach_res_control_context_s *foreach_context = user_data;
271 bool iteration_next = true;
273 if (res_type == NULL)
274 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
276 iteration_next = foreach_context->callback(res_type, min_res_version,
277 max_res_version, auto_close,
278 foreach_context->user_data);
279 if (iteration_next == true)
282 return PMINFO_R_ERROR;
285 int app_info_foreach_app_info(app_manager_app_info_cb callback, void *user_data)
287 foreach_context_s foreach_context = {
288 .callback = callback,
289 .user_data = user_data,
292 if (callback == NULL)
293 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
295 pkgmgrinfo_appinfo_get_usr_installed_list(app_info_foreach_app_info_cb, getuid(), &foreach_context);
297 return APP_MANAGER_ERROR_NONE;
300 static int _check_privilege(char *privilege)
305 char client[SMACK_LABEL_LEN + 1] = {0,};
307 char *client_session = "";
309 if (privilege == NULL) {
310 LOGE("invalid parameter");
311 return APP_MANAGER_ERROR_INVALID_PARAMETER;
314 ret = cynara_initialize(&p_cynara, NULL);
315 if (ret != CYNARA_API_SUCCESS) {
316 /* LCOV_EXCL_START */
317 LOGE("cynara_initialize [%d] failed!", ret);
318 return APP_MANAGER_ERROR_IO_ERROR;
322 fd = open("/proc/self/attr/current", O_RDONLY);
324 /* LCOV_EXCL_START */
325 LOGE("open [%d] failed!", errno);
326 ret = APP_MANAGER_ERROR_IO_ERROR;
331 ret = read(fd, client, SMACK_LABEL_LEN);
333 /* LCOV_EXCL_START */
334 LOGE("read [%d] failed!", errno);
336 ret = APP_MANAGER_ERROR_IO_ERROR;
341 snprintf(uid, 10, "%d", getuid());
343 ret = cynara_check(p_cynara, client, client_session, uid, privilege);
344 if (ret != CYNARA_API_ACCESS_ALLOWED) {
345 LOGE("cynara access check [%d] failed!", ret);
347 if (ret == CYNARA_API_ACCESS_DENIED)
348 ret = APP_MANAGER_ERROR_PERMISSION_DENIED;
350 ret = APP_MANAGER_ERROR_IO_ERROR;
354 ret = APP_MANAGER_ERROR_NONE;
358 cynara_finish(p_cynara);
363 static void __app_context_initialize(void)
365 pthread_mutex_lock(&__mutex);
366 if (__context.initialized) {
367 pthread_mutex_unlock(&__mutex);
371 if (getuid() < REGULAR_UID_MIN) {
372 __context.initialized = true;
373 pthread_mutex_unlock(&__mutex);
377 aul_app_get_appid_bypid(getpid(), __context.appid,
378 sizeof(__context.appid));
379 __context.initialized = true;
380 pthread_mutex_unlock(&__mutex);
383 static int __app_info_create_by_alias_appid(const char *app_id,
386 pkgmgrinfo_appinfo_h appinfo;
387 char *real_appid = NULL;
390 __app_context_initialize();
391 if (__context.appid[0] != '\0' && !strcmp(__context.appid, app_id))
392 return APP_MANAGER_ERROR_INVALID_PARAMETER;
394 ret = aul_svc_get_appid_by_alias_appid(app_id, &real_appid);
395 if (ret != AUL_SVC_RET_OK || real_appid == NULL)
396 return APP_MANAGER_ERROR_INVALID_PARAMETER;
398 /* LCOV_EXCL_START */
399 ret = pkgmgrinfo_appinfo_get_usr_appinfo(real_appid, getuid(),
402 if (ret != PMINFO_R_OK)
403 return APP_MANAGER_ERROR_INVALID_PARAMETER;
405 app_info->app_id = strdup(app_id);
406 app_info->pkg_app_info = appinfo;
409 return APP_MANAGER_ERROR_NONE;
412 API int app_info_create(const char *app_id, app_info_h *app_info)
414 pkgmgrinfo_pkginfo_h pkginfo = NULL;
415 pkgmgrinfo_appinfo_h appinfo = NULL;
416 app_info_h info = NULL;
418 char *main_appid = NULL;
420 if (app_id == NULL || app_info == NULL)
421 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
423 info = calloc(1, sizeof(struct app_info_s));
425 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
427 retval = __app_info_create_by_alias_appid(app_id, info);
428 if (retval == APP_MANAGER_ERROR_NONE) {
430 return APP_MANAGER_ERROR_NONE;
433 retval = pkgmgrinfo_appinfo_get_usr_appinfo(app_id, getuid(), &appinfo);
435 info->app_id = strdup(app_id);
436 info->pkg_app_info = appinfo;
438 return APP_MANAGER_ERROR_NONE;
441 retval = pkgmgrinfo_pkginfo_get_usr_pkginfo(app_id, getuid(), &pkginfo);
444 return app_manager_error(APP_MANAGER_ERROR_NO_SUCH_APP, __FUNCTION__, NULL);
447 retval = pkgmgrinfo_pkginfo_get_mainappid(pkginfo, &main_appid);
450 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
451 return app_manager_error(APP_MANAGER_ERROR_NO_SUCH_APP, __FUNCTION__, NULL);
453 if (pkgmgrinfo_appinfo_get_usr_appinfo(main_appid, getuid(), &appinfo)) {
455 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
456 return app_manager_error(APP_MANAGER_ERROR_NO_SUCH_APP, __FUNCTION__, NULL);
459 info->app_id = strdup(main_appid);
460 info->pkg_app_info = appinfo;
463 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
465 return APP_MANAGER_ERROR_NONE;
468 API int app_info_destroy(app_info_h app_info)
470 if (app_info == NULL)
471 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
473 if (app_info->app_id)
474 free(app_info->app_id);
476 pkgmgrinfo_appinfo_destroy_appinfo(app_info->pkg_app_info);
478 return APP_MANAGER_ERROR_NONE;
481 API int app_info_get_app_id(app_info_h app_info, char **app_id)
483 char *app_id_dup = NULL;
485 if (app_info == NULL || app_id == NULL)
486 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
488 if (app_info->app_id == NULL)
489 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
491 app_id_dup = strdup(app_info->app_id);
492 if (app_id_dup == NULL)
493 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
495 *app_id = app_id_dup;
497 return APP_MANAGER_ERROR_NONE;
500 API int app_info_get_exec(app_info_h app_info, char **exec)
503 char *app_exec_dup = NULL;
506 if (app_info == NULL || exec == NULL)
507 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
509 ret = pkgmgrinfo_appinfo_get_exec(app_info->pkg_app_info, &val);
510 if (ret != PMINFO_R_OK || val == NULL)
511 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
513 app_exec_dup = strdup(val);
514 if (app_exec_dup == NULL)
515 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
517 *exec = app_exec_dup;
519 return APP_MANAGER_ERROR_NONE;
522 API int app_info_get_label(app_info_h app_info, char **label)
525 char *app_label_dup = NULL;
528 if (app_info == NULL || label == NULL)
529 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
531 ret = pkgmgrinfo_appinfo_get_label(app_info->pkg_app_info, &val);
532 if (ret < 0 || val == NULL)
533 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
535 app_label_dup = strdup(val);
536 if (app_label_dup == NULL)
537 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
539 *label = app_label_dup;
541 return APP_MANAGER_ERROR_NONE;
544 API int app_info_get_localed_label(const char *app_id, const char *locale, char **label)
548 if (app_id == NULL || locale == NULL || label == NULL)
549 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
551 if (pkgmgrinfo_appinfo_usr_get_localed_label(app_id, locale, getuid(), &val))
552 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
556 return APP_MANAGER_ERROR_NONE;
559 API int app_info_get_icon(app_info_h app_info, char **path)
562 char *app_icon_dup = NULL;
565 if (app_info == NULL || path == NULL)
566 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
568 ret = pkgmgrinfo_appinfo_get_icon(app_info->pkg_app_info, &val);
569 if (ret != PMINFO_R_OK || val == NULL)
570 return APP_MANAGER_ERROR_INVALID_PARAMETER;
572 app_icon_dup = strdup(val);
573 if (app_icon_dup == NULL)
574 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
576 *path = app_icon_dup;
578 return APP_MANAGER_ERROR_NONE;
581 API int app_info_get_package(app_info_h app_info, char **package)
584 char *app_package_dup = NULL;
587 if (app_info == NULL || package == NULL)
588 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
590 ret = pkgmgrinfo_appinfo_get_pkgname(app_info->pkg_app_info, &val);
592 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
594 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
596 app_package_dup = strdup(val);
597 if (app_package_dup == NULL)
598 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
600 *package = app_package_dup;
602 return APP_MANAGER_ERROR_NONE;
605 API int app_info_get_type(app_info_h app_info, char **type)
608 char *app_type_dup = NULL;
611 if (app_info == NULL || type == NULL)
612 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
614 ret = pkgmgrinfo_appinfo_get_apptype(app_info->pkg_app_info, &val);
616 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
618 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
620 app_type_dup = strdup(val);
621 if (app_type_dup == NULL)
622 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
624 *type = app_type_dup;
626 return APP_MANAGER_ERROR_NONE;
629 API int app_info_get_app_component_type(app_info_h app_info, app_info_app_component_type_e *type)
631 pkgmgrinfo_app_component comp_val;
632 app_info_app_component_type_e converted_comp_val;
635 if (app_info == NULL || type == NULL)
636 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
638 ret = pkgmgrinfo_appinfo_get_component(app_info->pkg_app_info, &comp_val);
640 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
642 ret = app_info_convert_app_component(comp_val, &converted_comp_val);
644 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
646 *type = converted_comp_val;
648 return APP_MANAGER_ERROR_NONE;
651 API int app_info_foreach_metadata(app_info_h app_info, app_info_metadata_cb callback, void *user_data)
655 if (app_info == NULL || callback == NULL)
656 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
658 foreach_metadata_context_s foreach_context = {
659 .callback = callback,
660 .user_data = user_data,
663 retval = pkgmgrinfo_appinfo_foreach_metadata(app_info->pkg_app_info, app_info_foreach_app_metadata_cb, &foreach_context);
665 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
667 return APP_MANAGER_ERROR_NONE;
670 API int app_info_is_nodisplay(app_info_h app_info, bool *nodisplay)
674 if (app_info == NULL || nodisplay == NULL)
675 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
677 if (pkgmgrinfo_appinfo_is_nodisplay(app_info->pkg_app_info, &val) < 0)
678 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
681 return APP_MANAGER_ERROR_NONE;
684 API int app_info_is_enabled(app_info_h app_info, bool *enabled)
688 if (app_info == NULL || enabled == NULL)
689 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
691 if (pkgmgrinfo_appinfo_is_enabled(app_info->pkg_app_info, &val) < 0)
692 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
695 return APP_MANAGER_ERROR_NONE;
699 API int app_info_is_equal(app_info_h lhs, app_info_h rhs, bool *equal)
701 if (lhs == NULL || rhs == NULL || equal == NULL)
702 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
704 if (!strcmp(lhs->app_id, rhs->app_id))
709 return APP_MANAGER_ERROR_NONE;
712 API int app_info_is_onboot(app_info_h app_info, bool *onboot)
716 if (app_info == NULL || onboot == NULL)
717 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
719 if (pkgmgrinfo_appinfo_is_onboot(app_info->pkg_app_info, &val) < 0)
720 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
723 return APP_MANAGER_ERROR_NONE;
726 API int app_info_is_preload(app_info_h app_info, bool *preload)
730 if (app_info == NULL || preload == NULL)
731 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
733 if (pkgmgrinfo_appinfo_is_preload(app_info->pkg_app_info, &val) < 0)
734 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
737 return APP_MANAGER_ERROR_NONE;
740 API int app_info_is_support_ambient(app_info_h app_info, bool *support_ambient)
744 if (app_info == NULL || support_ambient == NULL)
745 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
747 if (pkgmgrinfo_appinfo_is_support_ambient(app_info->pkg_app_info, &val) < 0)
748 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
750 *support_ambient = val;
751 return APP_MANAGER_ERROR_NONE;
754 API int app_info_clone(app_info_h *clone, app_info_h app_info)
758 if (clone == NULL || app_info == NULL)
759 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
761 info = calloc(1, sizeof(struct app_info_s));
763 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
765 info->app_id = strdup(app_info->app_id);
766 if (info->app_id == NULL) {
767 /* LCOV_EXCL_START */
769 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
773 if (pkgmgrinfo_appinfo_clone_appinfo(app_info->pkg_app_info, &(info->pkg_app_info)) < 0) {
774 /* LCOV_EXCL_START */
777 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
783 return APP_MANAGER_ERROR_NONE;
786 API int app_info_foreach_category(app_info_h app_info, app_info_category_cb callback, void *user_data)
789 if (app_info == NULL || callback == NULL)
790 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
792 retval = _check_privilege(PRIVILEGE_PACKAGE_MANAGER_ADMIN);
793 if (retval != APP_MANAGER_ERROR_NONE)
794 return app_manager_error(APP_MANAGER_ERROR_PERMISSION_DENIED, __FUNCTION__, NULL);
796 foreach_category_context_s foreach_category = {
797 .callback = callback,
798 .user_data = user_data,
801 retval = pkgmgrinfo_appinfo_foreach_category(app_info->pkg_app_info, app_info_foreach_category_cb, &foreach_category);
802 if (retval != PMINFO_R_OK)
803 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
805 return APP_MANAGER_ERROR_NONE;
808 API int app_info_filter_create(app_info_filter_h *handle)
811 app_info_filter_h filter_created = NULL;
812 pkgmgrinfo_appinfo_filter_h filter_h = NULL;
815 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
817 retval = pkgmgrinfo_appinfo_filter_create(&filter_h);
819 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
821 filter_created = calloc(1, sizeof(struct app_info_filter_s));
822 if (filter_created == NULL) {
823 /* LCOV_EXCL_START */
825 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
829 filter_created->pkg_app_info_filter = filter_h;
831 *handle = filter_created;
833 return APP_MANAGER_ERROR_NONE;
836 API int app_info_filter_destroy(app_info_filter_h handle)
841 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
843 retval = pkgmgrinfo_appinfo_filter_destroy(handle->pkg_app_info_filter);
845 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
848 return APP_MANAGER_ERROR_NONE;
851 API int app_info_filter_add_bool(app_info_filter_h handle, const char *property, const bool value)
854 char *converted_property = NULL;
856 if ((handle == NULL) || (property == NULL))
857 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
859 retval = app_info_convert_bool_property(property, &converted_property);
861 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
863 retval = pkgmgrinfo_appinfo_filter_add_bool(handle->pkg_app_info_filter, converted_property, value);
865 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
867 return APP_MANAGER_ERROR_NONE;
870 API int app_info_filter_add_string(app_info_filter_h handle, const char *property, const char *value)
873 char *converted_property = NULL;
875 if ((handle == NULL) || (property == NULL))
876 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
878 retval = app_info_convert_str_property(property, &converted_property);
880 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
882 retval = pkgmgrinfo_appinfo_filter_add_string(handle->pkg_app_info_filter, converted_property, value);
884 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
886 return APP_MANAGER_ERROR_NONE;
889 API int app_info_filter_count_appinfo(app_info_filter_h handle, int *count)
893 if ((handle == NULL) || (count == NULL))
894 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
896 retval = pkgmgrinfo_appinfo_filter_count(handle->pkg_app_info_filter, count);
898 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
900 return APP_MANAGER_ERROR_NONE;
903 API int app_info_filter_foreach_appinfo(app_info_filter_h handle, app_info_filter_cb callback, void *user_data)
907 foreach_context_s foreach_context = {
908 .callback = callback,
909 .user_data = user_data,
912 if ((handle == NULL) || (callback == NULL))
913 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
915 retval = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle->pkg_app_info_filter, app_info_foreach_app_filter_cb, &foreach_context, getuid());
917 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
919 return APP_MANAGER_ERROR_NONE;
922 API int app_info_metadata_filter_create(app_info_metadata_filter_h *handle)
925 app_info_metadata_filter_h filter_created = NULL;
926 pkgmgrinfo_appinfo_metadata_filter_h filter_h = NULL;
929 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
931 filter_created = calloc(1, sizeof(struct app_info_metadata_filter_s));
932 if (filter_created == NULL)
933 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
935 retval = pkgmgrinfo_appinfo_metadata_filter_create(&filter_h);
937 /* LCOV_EXCL_START */
938 free(filter_created);
939 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
943 filter_created->pkg_app_info_metadata_filter = filter_h;
945 *handle = filter_created;
947 return APP_MANAGER_ERROR_NONE;
950 API int app_info_metadata_filter_destroy(app_info_metadata_filter_h handle)
955 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
957 retval = pkgmgrinfo_appinfo_metadata_filter_destroy(handle->pkg_app_info_metadata_filter);
959 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
962 return APP_MANAGER_ERROR_NONE;
965 API int app_info_metadata_filter_add(app_info_metadata_filter_h handle, const char *key, const char *value)
969 if ((handle == NULL) || (key == NULL))
970 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
972 retval = pkgmgrinfo_appinfo_metadata_filter_add(handle->pkg_app_info_metadata_filter, key, value);
974 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
976 return APP_MANAGER_ERROR_NONE;
979 API int app_info_metadata_filter_foreach(app_info_metadata_filter_h handle, app_info_filter_cb callback, void *user_data)
983 foreach_context_s foreach_context = {
984 .callback = callback,
985 .user_data = user_data,
989 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
991 if (callback == NULL)
992 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
994 retval = pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle->pkg_app_info_metadata_filter, app_info_foreach_app_filter_cb, &foreach_context, getuid());
996 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */
998 return APP_MANAGER_ERROR_NONE;
1001 API int app_info_foreach_res_control(app_info_h app_info, app_info_res_control_cb callback, void *user_data)
1005 if (app_info == NULL || callback == NULL)
1006 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
1008 foreach_res_control_context_s foreach_context = {
1009 .callback = callback,
1010 .user_data = user_data,
1013 retval = pkgmgrinfo_appinfo_foreach_res_control(app_info->pkg_app_info, app_info_foreach_res_control_cb, &foreach_context);
1015 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
1017 return APP_MANAGER_ERROR_NONE;