Add package_manager_clear_data API for extension 25/97425/4 accepted/tizen/3.0/common/20161124.181433 accepted/tizen/3.0/ivi/20161124.024600 accepted/tizen/3.0/mobile/20161124.024456 accepted/tizen/3.0/tv/20161124.024523 accepted/tizen/3.0/wearable/20161124.024544 accepted/tizen/common/20161125.095113 accepted/tizen/ivi/20161125.004131 accepted/tizen/mobile/20161125.003537 accepted/tizen/tv/20161125.003859 accepted/tizen/wearable/20161125.004013 submit/tizen/20161124.000829 submit/tizen_3.0/20161122.002346
authorJunghyun Yeon <jungh.yeon@samsung.com>
Mon, 14 Nov 2016 07:01:04 +0000 (16:01 +0900)
committerjongmyeong ko <jongmyeong.ko@samsung.com>
Wed, 23 Nov 2016 01:13:27 +0000 (17:13 -0800)
Change-Id: Ifd84d152d530b67c038a0cad468d93c95eed0509
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
include/package_manager_extension.h [new file with mode: 0644]
src/package_manager.c

diff --git a/include/package_manager_extension.h b/include/package_manager_extension.h
new file mode 100644 (file)
index 0000000..6a0a708
--- /dev/null
@@ -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 <package_manager.h>
+
+#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 */
index d44783f..80f3041 100644 (file)
@@ -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)
 {