2 * Copyright (c) 2011 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.
19 #include <package-manager.h>
20 #include <pkgmgr-info.h>
21 #include <tzplatform_config.h>
23 #include "package_info.h"
24 #include "package_manager.h"
25 #include "package_manager_internal.h"
27 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
29 typedef struct _foreach_pkg_context_{
30 package_manager_package_info_cb callback;
32 } foreach_pkg_context_s;
34 static const char *package_manager_error_to_string(package_manager_error_e
38 case PACKAGE_MANAGER_ERROR_NONE:
40 case PACKAGE_MANAGER_ERROR_INVALID_PARAMETER:
41 return "INVALID_PARAMETER";
42 case PACKAGE_MANAGER_ERROR_OUT_OF_MEMORY:
43 return "OUT_OF_MEMORY";
44 case PACKAGE_MANAGER_ERROR_IO_ERROR:
46 case PACKAGE_MANAGER_ERROR_NO_SUCH_PACKAGE:
47 return "NO_SUCH_PACKAGE";
48 case PACKAGE_MANAGER_ERROR_PERMISSION_DENIED:
49 return "PERMISSION_DENIED";
50 case PACKAGE_MANAGER_ERROR_SYSTEM_ERROR:
51 return "SEVERE_SYSTEM_ERROR";
57 int package_manager_error(package_manager_error_e error,
58 const char *function, const char *description)
61 _LOGE("[%s] %s(0x%08x) : %s", function,
62 package_manager_error_to_string(error), error,
65 _LOGE("[%s] %s(0x%08x)", function,
66 package_manager_error_to_string(error), error);
72 int package_info_get_package_info(const char *package, package_info_h *package_info)
74 return package_info_create(package, package_info);
77 static int package_info_foreach_package_info_cb(const pkgmgr_pkginfo_h handle, void *user_data)
79 char *pkg_name = NULL;
80 foreach_pkg_context_s *foreach_pkg_context = user_data;
81 package_info_h package_info = NULL;
84 if (handle == NULL || foreach_pkg_context == NULL)
86 package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
87 return PKGMGR_R_EINVAL;
90 pkgmgr_pkginfo_get_pkgname(handle, &pkg_name);
92 if (package_info_create(pkg_name, &package_info) == PACKAGE_MANAGER_ERROR_NONE)
94 r = foreach_pkg_context->callback(package_info, foreach_pkg_context->user_data);
95 package_info_destroy(package_info);
98 return (r == true) ? PKGMGR_R_OK : PKGMGR_R_ERROR;
101 int package_info_foreach_package_info(package_manager_package_info_cb callback, void *user_data)
103 foreach_pkg_context_s foreach_pkg_context = {
104 .callback = callback,
105 .user_data = user_data,
109 if (callback == NULL)
111 return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
113 uid_t uid = getuid();
114 if (uid != GLOBAL_USER)
115 ret = pkgmgr_pkginfo_get_usr_list(package_info_foreach_package_info_cb, &foreach_pkg_context, uid);
117 ret = pkgmgr_pkginfo_get_list(package_info_foreach_package_info_cb, &foreach_pkg_context);
119 return PACKAGE_MANAGER_ERROR_NO_SUCH_PACKAGE;
122 return PACKAGE_MANAGER_ERROR_NONE;
125 int package_info_filter_foreach_package_info(pkgmgrinfo_pkginfo_filter_h handle, package_manager_package_info_cb callback, void *user_data)
127 foreach_pkg_context_s foreach_pkg_context = {
128 .callback = callback,
129 .user_data = user_data,
134 if ((handle == NULL) || (callback == NULL))
135 return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
138 if (uid != GLOBAL_USER)
139 ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, package_info_foreach_package_info_cb, &foreach_pkg_context, uid);
141 ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, package_info_foreach_package_info_cb, &foreach_pkg_context);
144 return PACKAGE_MANAGER_ERROR_IO_ERROR;
146 return PACKAGE_MANAGER_ERROR_NONE;