Add mount-install API as extension feature in tizen 4.0 93/137993/2
authorjongmyeongko <jongmyeong.ko@samsung.com>
Mon, 10 Jul 2017 12:50:40 +0000 (21:50 +0900)
committerjongmyeong ko <jongmyeong.ko@samsung.com>
Tue, 11 Jul 2017 01:40:07 +0000 (01:40 +0000)
Change-Id: Ie5b136ea12f5cb13478d9d3ba73e40f557de74f4
Signed-off-by: jongmyeongko <jongmyeong.ko@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..fe610fe
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2017 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_EXTENSION_H
+#define __TIZEN_APPFW_PACKAGE_MANAGER_EXTENSION_H
+
+#include "package_manager.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file package_manager_extension.h
+ */
+
+/**
+ * @addtogroup CAPI_PACKAGE_MANAGER_MODULE
+ * @{
+ */
+
+/**
+ * @platform
+ * @brief Installs the package located at the given path as the runtime mountable package, asynchronously.
+ * @since_tizen 4.0
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/packagemanager.admin
+ * @param[in]  request The request handle
+ * @param[in]  path    The absolute path to the package to be installed
+ * @param[out] id      The ID of the request to the package manager
+ * @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_PERMISSION_DENIED Permission denied
+ * @see package_manager_request_uninstall()
+ */
+int package_manager_request_mount_install(package_manager_request_h request, const char *path, int *id);
+
+
+/**
+ * @platform
+ * @brief Installs the package located at the given path as the runtime mountable package, asynchronously.
+ * @details The progress of the request is asynchronously received by the callback function.
+ *          The @a callback is the individual callback only called for the current API call.
+ *          The @a callback is the only callback called, even if another callback was set for this request
+ *          with package_manager_request_set_event_cb().
+ * @since_tizen 4.0
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/packagemanager.admin
+ * @param[in]  request   The request handle
+ * @param[in]  path      The absolute path to the package to be installed
+ * @param[in]  callback  The callback function to be invoked
+ * @param[in]  user_data The user data to be passed to the callback function
+ * @param[out] id        The ID of the request to the package manager
+ * @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_PERMISSION_DENIED Permission denied
+ */
+int package_manager_request_mount_install_with_cb(package_manager_request_h request,
+                                               const char *path,
+                                               package_manager_request_event_cb callback,
+                                               void *user_data,
+                                               int *id);
+
+/**
+* @}
+*/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_PACKAGE_MANAGER_EXTENSION_H */
index 3cf4bde..116d0b2 100644 (file)
@@ -755,6 +755,44 @@ static int __request_move(package_manager_request_h request,
        return PACKAGE_MANAGER_ERROR_NONE;
 }
 
+static int __request_mount_install(package_manager_request_h request,
+               const char *path, pkgmgr_handler event_cb, int *id)
+{
+       int retval;
+       retval = check_privilege(PRIVILEGE_PACKAGE_MANAGER_ADMIN);
+       if (retval != PACKAGE_MANAGER_ERROR_NONE)
+               return retval;
+
+       if (package_manager_client_validate_handle(request))
+               return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+       if (path == NULL)
+               return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+       int request_id = 0;
+       request_id = pkgmgr_client_mount_install(request->pc, request->pkg_type, NULL,
+                       path, NULL, request->mode, event_cb ? event_cb : request_event_handler, request);
+
+       if (request_id == PKGMGR_R_EINVAL)
+               return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       else if (request_id == PKGMGR_R_ENOPKG)
+               return package_manager_error(PACKAGE_MANAGER_ERROR_NO_SUCH_PACKAGE, __FUNCTION__, NULL);
+       else if (request_id == PKGMGR_R_ENOMEM)
+               return package_manager_error(PACKAGE_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
+       else if (request_id == PKGMGR_R_EIO)
+               return package_manager_error(PACKAGE_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
+       else if (request_id == PKGMGR_R_EPRIV)
+               return package_manager_error(PACKAGE_MANAGER_ERROR_PERMISSION_DENIED, __FUNCTION__, NULL);
+       else if (request_id == PKGMGR_R_ESYSTEM || request_id == PKGMGR_R_ECOMM || request_id == PKGMGR_R_ERROR)
+               return package_manager_error(PACKAGE_MANAGER_ERROR_SYSTEM_ERROR, __FUNCTION__, NULL);
+
+       if (id)
+               *id = request_id;
+
+       return PACKAGE_MANAGER_ERROR_NONE;
+}
+
+
 API int package_manager_request_install(package_manager_request_h request,
                                const char *path, int *id)
 {
@@ -845,6 +883,36 @@ API int package_manager_request_move_with_cb(package_manager_request_h request,
        return ret;
 }
 
+API int package_manager_request_mount_install(package_manager_request_h request,
+                               const char *path, int *id)
+{
+       return __request_mount_install(request, path, NULL, id);
+}
+
+API int package_manager_request_mount_install_with_cb(package_manager_request_h request,
+                       const char *path, package_manager_request_event_cb callback,
+                       void *user_data, int *id)
+{
+       int ret;
+       int req_id = 0;
+
+       if (request->request_cb_table == NULL)
+               __initialize_request_cb_table(request);
+
+       ret = __request_mount_install(request, path, internal_request_callback, &req_id);
+
+       if (req_id > 0) {
+               ret = __insert_request_cb_info(request, req_id, callback, user_data);
+               if (ret < 0)
+                       return package_manager_error(PACKAGE_MANAGER_ERROR_OUT_OF_MEMORY,
+                                       __FUNCTION__, "failed to create request cb info");
+               if (id)
+                       *id = req_id;
+       }
+
+       return ret;
+}
+
 API int package_manager_create(package_manager_h *manager)
 {
        int retval;