From 1bb843ad1ade7427bfcf70a244a92f56bee8bfaf Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Mon, 14 Nov 2016 16:01:04 +0900 Subject: [PATCH] Add package_manager_clear_data API for extension Change-Id: Ifd84d152d530b67c038a0cad468d93c95eed0509 Signed-off-by: Junghyun Yeon --- include/package_manager_extension.h | 67 +++++++++++++++++++++++++++++++++++++ src/package_manager.c | 43 ++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 include/package_manager_extension.h diff --git a/include/package_manager_extension.h b/include/package_manager_extension.h new file mode 100644 index 0000000..6a0a708 --- /dev/null +++ b/include/package_manager_extension.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __TIZEN_APPFW_PACKAGE_MANAGER_H +#define __TIZEN_APPFW_PACKAGE_MANAGER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file package_manager_extension.h + */ + +/** + * @addtogroup CAPI_PACKAGE_MANAGER_MODULE + * @{ + */ + +/** + * @brief Clears the application's userdata. + * @details All userdatas of the application specified with the + * package ID are removed. + * + * @since_tizen 3.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/packagemanager.admin + * + * @param[in] package_id The package ID + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #PACKAGE_MANAGER_ERROR_NONE Successful + * @retval #PACKAGE_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PACKAGE_MANAGER_ERROR_NO_SUCH_PACKAGE No such package + * @retval #PACKAGE_MANAGER_ERROR_PERMISSION_DENIED Permission denied + * @retval #PACKAGE_MANAGER_ERROR_OUT_OF_MEMORY Out of memory + * @retval #PACKAGE_MANAGER_ERROR_IO_ERROR I/O error + * @retval #PACKAGE_MANAGER_ERROR_SYSTEM_ERROR Severe system error + */ +int package_manager_clear_data(const char *package_id); + +/** +* @} +*/ + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_APPFW_PACKAGE_MANAGER_H */ diff --git a/src/package_manager.c b/src/package_manager.c index d44783f..80f3041 100644 --- a/src/package_manager.c +++ b/src/package_manager.c @@ -1082,6 +1082,49 @@ API int package_manager_clear_cache_dir(const char *package_id) return PACKAGE_MANAGER_ERROR_NONE; } +API int package_manager_clear_data(const char *package_id) +{ + int retval; + pkgmgr_client *pc = NULL; + char *pkg_type = NULL; + pkgmgrinfo_pkginfo_h pkginfo = NULL; + + if (package_id == NULL) + return PACKAGE_MANAGER_ERROR_INVALID_PARAMETER; + + retval = check_privilege(PRIVILEGE_PACKAGE_MANAGER_ADMIN); + if (retval != PACKAGE_MANAGER_ERROR_NONE) + return retval; + + retval = pkgmgrinfo_pkginfo_get_pkginfo(package_id, &pkginfo); + if (retval == PMINFO_R_ENOENT) + return PACKAGE_MANAGER_ERROR_NO_SUCH_PACKAGE; + else if (retval != PMINFO_R_OK || pkginfo == NULL) + return PACKAGE_MANAGER_ERROR_SYSTEM_ERROR; + + retval = pkgmgrinfo_pkginfo_get_type(pkginfo, &pkg_type); + if (retval != PMINFO_R_OK || pkg_type == NULL) { + pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo); + return PACKAGE_MANAGER_ERROR_SYSTEM_ERROR; + } + + pc = pkgmgr_client_new(PC_REQUEST); + if (pc == NULL) { + _LOGE("Out of memory"); + pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo); + return PACKAGE_MANAGER_ERROR_OUT_OF_MEMORY; + } + + retval = pkgmgr_client_clear_user_data(pc, pkg_type, package_id, PM_QUIET); + pkgmgr_client_free(pc); + pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo); + + if (retval != PKGMGR_R_OK) + return PACKAGE_MANAGER_ERROR_IO_ERROR; + + return PACKAGE_MANAGER_ERROR_NONE; +} + API int package_manager_clear_all_cache_dir(void) { -- 2.7.4