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.
23 #include <package-manager.h>
24 #include <pkgmgr-info.h>
25 #include <tzplatform_config.h>
27 #include "package_info.h"
28 #include "package_manager.h"
29 #include "package_manager_internal.h"
31 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
33 struct package_info_s {
35 pkgmgr_pkginfo_h pkgmgr_pkginfo;
38 struct package_cert_info_s {
40 pkgmgrinfo_certinfo_h pkgmgrinfo_certinfo;
43 typedef struct _foreach_app_context_{
44 package_info_app_cb callback;
46 } foreach_app_context_s;
48 API int package_info_create(const char *package, package_info_h *package_info)
50 package_info_h package_info_created;
51 pkgmgr_pkginfo_h pkgmgr_pkginfo;
54 if (package == NULL || package_info == NULL)
56 return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
59 if (uid != GLOBAL_USER)
61 if (pkgmgr_pkginfo_get_usr_pkginfo(package, uid, &pkgmgr_pkginfo) != PKGMGR_R_OK)
62 return package_manager_error(PACKAGE_MANAGER_ERROR_NO_SUCH_PACKAGE, __FUNCTION__, NULL);
66 if (pkgmgr_pkginfo_get_pkginfo(package, &pkgmgr_pkginfo) != PKGMGR_R_OK)
67 return package_manager_error(PACKAGE_MANAGER_ERROR_NO_SUCH_PACKAGE, __FUNCTION__, NULL);
69 package_info_created = calloc(1, sizeof(struct package_info_s));
71 if (package_info_created == NULL)
73 pkgmgr_pkginfo_destroy_pkginfo(pkgmgr_pkginfo);
74 return package_manager_error(PACKAGE_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
77 package_info_created->package = strdup(package);
79 if (package_info_created->package == NULL)
81 pkgmgr_pkginfo_destroy_pkginfo(pkgmgr_pkginfo);
82 free(package_info_created);
83 return package_manager_error(PACKAGE_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
86 package_info_created->pkgmgr_pkginfo = pkgmgr_pkginfo;
88 *package_info = package_info_created;
90 return PACKAGE_MANAGER_ERROR_NONE;
93 static int package_info_foreach_app_cb (const pkgmgr_appinfo_h handle, void *user_data)
96 pkgmgr_app_component comp;
97 foreach_app_context_s *foreach_app_context = user_data;
100 if (handle == NULL || foreach_app_context == NULL)
102 package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
103 return PKGMGR_R_EINVAL;
106 ret = pkgmgr_appinfo_get_appid(handle, &appid);
108 return PKGMGR_R_ERROR;
110 ret = pkgmgr_appinfo_get_component(handle, &comp);
112 return PKGMGR_R_ERROR;
115 foreach_app_context->callback(comp, appid, foreach_app_context->user_data);
120 API int package_info_foreach_app_from_package(package_info_h package_info, package_info_app_component_type_e comp_type, package_info_app_cb callback, void *user_data)
122 foreach_app_context_s foreach_app_context = {
123 .callback = callback,
124 .user_data = user_data,
126 pkgmgr_pkginfo_h pkgmgr_pkginfo;
127 uid_t uid = getuid();
129 if (package_info == NULL || callback == NULL)
131 return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
134 if (pkgmgr_pkginfo_get_usr_pkginfo(package_info->package,uid,&pkgmgr_pkginfo) != PKGMGR_R_OK)
136 return package_manager_error(PACKAGE_MANAGER_ERROR_NO_SUCH_PACKAGE, __FUNCTION__, NULL);
138 if (comp_type == PACKAGE_INFO_ALLAPP)
139 pkgmgr_appinfo_get_list(pkgmgr_pkginfo, PM_ALL_APP, package_info_foreach_app_cb, &foreach_app_context);
140 if (comp_type == PACKAGE_INFO_UIAPP)
141 pkgmgr_appinfo_get_list(pkgmgr_pkginfo, PM_UI_APP, package_info_foreach_app_cb, &foreach_app_context);
142 if (comp_type == PACKAGE_INFO_SERVICEAPP)
143 pkgmgr_appinfo_get_list(pkgmgr_pkginfo, PM_SVC_APP, package_info_foreach_app_cb, &foreach_app_context);
144 return PACKAGE_MANAGER_ERROR_NONE;
147 API int package_info_destroy(package_info_h package_info)
149 if (package_info == NULL)
151 return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
154 free(package_info->package);
156 pkgmgr_pkginfo_destroy_pkginfo(package_info->pkgmgr_pkginfo);
160 return PACKAGE_MANAGER_ERROR_NONE;
163 API int package_info_get_package(package_info_h package_info, char **package)
167 if (package_info == NULL || package == NULL)
169 return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
172 package_dup = strdup(package_info->package);
174 if (package_dup == NULL)
176 return package_manager_error(PACKAGE_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
179 *package = package_dup;
181 return PACKAGE_MANAGER_ERROR_NONE;
184 API int package_info_get_label(package_info_h package_info, char **label)
186 char *pkg_info_value = NULL;
187 char *label_dup = NULL;
189 if (package_info == NULL || label == NULL)
191 return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
194 if (pkgmgr_pkginfo_get_label(package_info->pkgmgr_pkginfo, &pkg_info_value) != PKGMGR_R_OK)
196 return package_manager_error(PACKAGE_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
202 label_dup = strdup(pkg_info_value);
204 if (label_dup == NULL)
206 return package_manager_error(PACKAGE_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
212 return PACKAGE_MANAGER_ERROR_NONE;
215 API int package_info_get_icon(package_info_h package_info, char **path)
217 char *pkg_info_value = NULL;
218 char *icon_dup = NULL;
220 if (package_info == NULL || path == NULL)
222 return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
225 if (pkgmgr_pkginfo_get_icon(package_info->pkgmgr_pkginfo, &pkg_info_value) != PKGMGR_R_OK)
227 return package_manager_error(PACKAGE_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
233 icon_dup = strdup(pkg_info_value);
235 if (icon_dup == NULL)
237 return package_manager_error(PACKAGE_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
243 return PACKAGE_MANAGER_ERROR_NONE;
246 API int package_info_get_version(package_info_h package_info, char **version)
248 char *pkg_info_value = NULL;
249 char *ver_dup = NULL;
251 if (package_info == NULL || version == NULL)
253 return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
256 if (pkgmgr_pkginfo_get_version(package_info->pkgmgr_pkginfo, &pkg_info_value) != PKGMGR_R_OK)
258 return package_manager_error(PACKAGE_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
264 ver_dup = strdup(pkg_info_value);
268 return package_manager_error(PACKAGE_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
274 return PACKAGE_MANAGER_ERROR_NONE;
277 API int package_info_get_type(package_info_h package_info, char **type)
279 char *pkg_info_value = NULL;
280 char *type_dup = NULL;
282 if (package_info == NULL || type == NULL)
284 return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
287 if (pkgmgr_pkginfo_get_type(package_info->pkgmgr_pkginfo, &pkg_info_value) != PKGMGR_R_OK)
289 return package_manager_error(PACKAGE_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
295 type_dup = strdup(pkg_info_value);
297 if (type_dup == NULL)
299 return package_manager_error(PACKAGE_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
305 return PACKAGE_MANAGER_ERROR_NONE;
308 API int package_info_get_installed_storage(package_info_h package_info, package_info_installed_storage_type_e *storage)
311 pkgmgr_installed_storage pkg_info_value;
313 if (package_info == NULL || storage == NULL)
315 return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
318 ret = pkgmgr_pkginfo_get_installed_storage(package_info->pkgmgr_pkginfo, &pkg_info_value);
320 return package_manager_error(PACKAGE_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
322 if (pkg_info_value == PM_INTERNAL_STORAGE)
323 *storage = PACKAGE_INFO_INTERNAL_STORAGE;
324 else if (pkg_info_value == PM_EXTERNAL_STORAGE)
325 *storage = PACKAGE_INFO_EXTERNAL_STORAGE;
327 return PACKAGE_MANAGER_ERROR_NONE;
330 API int package_info_get_root_path(package_info_h package_info, char **path)
332 char *pkg_info_value = NULL;
333 char *path_dup = NULL;
335 if (package_info == NULL || path == NULL)
337 return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
340 if (pkgmgrinfo_pkginfo_get_root_path(package_info->pkgmgr_pkginfo, &pkg_info_value) != PKGMGR_R_OK)
342 return package_manager_error(PACKAGE_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
348 path_dup = strdup(pkg_info_value);
350 if (path_dup == NULL)
352 return package_manager_error(PACKAGE_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
358 return PACKAGE_MANAGER_ERROR_NONE;
361 API int package_info_is_system_package(package_info_h package_info, bool *system)
363 bool pkg_info_value = false;
365 if (package_info == NULL || system == NULL)
367 return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
370 if (pkgmgr_pkginfo_is_preload(package_info->pkgmgr_pkginfo, &pkg_info_value) != PKGMGR_R_OK)
372 return package_manager_error(PACKAGE_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
375 *system = pkg_info_value;
377 return PACKAGE_MANAGER_ERROR_NONE;
380 API int package_info_is_removable_package(package_info_h package_info, bool *removable)
382 bool pkg_info_value = false;
384 if (package_info == NULL || removable == NULL)
386 return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
389 if (pkgmgr_pkginfo_is_removable(package_info->pkgmgr_pkginfo, &pkg_info_value) != PKGMGR_R_OK)
391 return package_manager_error(PACKAGE_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
394 *removable = pkg_info_value;
396 return PACKAGE_MANAGER_ERROR_NONE;
399 API int package_info_is_preload_package(package_info_h package_info, bool *preload)
401 bool pkg_info_value = false;
403 if (package_info == NULL || preload == NULL)
405 return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
408 if (pkgmgr_pkginfo_is_preload(package_info->pkgmgr_pkginfo, &pkg_info_value) != PKGMGR_R_OK)
410 return package_manager_error(PACKAGE_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
413 *preload = pkg_info_value;
415 return PACKAGE_MANAGER_ERROR_NONE;
418 API int package_info_is_equal(package_info_h lhs, package_info_h rhs, bool *equal)
420 if (lhs == NULL || rhs == NULL || equal == NULL)
422 return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
425 if (!strcmp(lhs->package, rhs->package))
434 return PACKAGE_MANAGER_ERROR_NONE;
437 API int package_info_is_accessible(package_info_h package_info, bool *accessible)
440 bool pkg_info_value = false;
442 if (package_info == NULL || accessible == NULL)
444 return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
447 ret = pkgmgr_pkginfo_is_accessible(package_info->pkgmgr_pkginfo, &pkg_info_value);
449 return package_manager_error(PACKAGE_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
452 *accessible = pkg_info_value;
454 return PACKAGE_MANAGER_ERROR_NONE;
457 API int package_info_clone(package_info_h *clone, package_info_h package_info)
461 if (clone == NULL || package_info == NULL)
463 return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
466 retval = package_info_create(package_info->package, clone);
468 if (retval != PACKAGE_MANAGER_ERROR_NONE)
470 return package_manager_error(retval, __FUNCTION__, NULL);
473 return PACKAGE_MANAGER_ERROR_NONE;
476 API int package_info_foreach_cert_info(package_info_h package_info, package_info_cert_info_cb callback, void *user_data)
479 pkgmgrinfo_certinfo_h handle = NULL;
481 const char *cert_value = NULL;
482 uid_t uid = getuid();
484 if (package_info == NULL || callback == NULL)
486 return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
489 retval = pkgmgrinfo_pkginfo_create_certinfo(&handle);
490 if (retval != PMINFO_R_OK)
491 return package_manager_error(PACKAGE_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
493 retval = pkgmgrinfo_pkginfo_load_certinfo(package_info->package, handle, uid);
494 if (retval != PMINFO_R_OK)
496 pkgmgrinfo_pkginfo_destroy_certinfo(handle);
497 return package_manager_error(PACKAGE_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
500 for( i=0; i<=PACKAGE_INFO_DISTRIBUTOR2_SIGNER_CERT; i++)
502 retval = pkgmgrinfo_pkginfo_get_cert_value(handle, i, &cert_value);
503 if (retval != PMINFO_R_OK)
505 pkgmgrinfo_pkginfo_destroy_certinfo(handle);
506 return package_manager_error(PACKAGE_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
509 if ( cert_value && strncmp(cert_value, "(null)", strlen("(null)")) )
511 retval = callback(package_info, (package_cert_type_e)i, cert_value, user_data);
519 pkgmgrinfo_pkginfo_destroy_certinfo(handle);
521 return PACKAGE_MANAGER_ERROR_NONE;
524 API int package_info_foreach_privilege_info(package_info_h package_info, package_info_privilege_info_cb callback, void *user_data)
528 if (package_info == NULL || callback == NULL)
530 return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
533 ret = pkgmgrinfo_pkginfo_foreach_privilege(package_info->pkgmgr_pkginfo, callback, user_data);