Add package_info_get_main_app_id as extension 56/123556/4
authorJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 6 Apr 2017 05:45:08 +0000 (14:45 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 14 Apr 2017 04:09:11 +0000 (21:09 -0700)
- Add package_info_get_main_app_id API as extension to get main appid of package

Change-Id: I9aa415cd1abf523f184560da3805e3c5bc4721a1
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
include/package_info_extension.h [new file with mode: 0644]
src/package_info.c

diff --git a/include/package_info_extension.h b/include/package_info_extension.h
new file mode 100644 (file)
index 0000000..90e1c5a
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * 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_INFO_EXTENSION_H
+#define __TIZEN_APPFW_PACKAGE_INFO_EXTENSION_H
+
+#include "package_info.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file package_info_extension.h
+ */
+
+/**
+ * @addtogroup CAPI_PACKAGE_INFO_MODULE
+ * @{
+ */
+
+/**
+ * @brief Gets the main application ID of the package.
+ * @since_tizen 4.0
+ * @remarks You must release @a main_app_id using free().
+ * @param[in]  package_info     The package information
+ * @param[out] main_app_id      The main application ID of the package
+ * @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_OUT_OF_MEMORY     Out of memory
+ * @retval #PACKAGE_MANAGER_ERROR_IO_ERROR          I/O error
+ */
+int package_info_get_main_app_id(package_info_h package_info, char **main_app_id);
+
+/**
+* @}
+*/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_PACKAGE_INFO_EXTENSION_H */
index 8cb1cd8..9d48ad7 100644 (file)
@@ -152,6 +152,26 @@ API int package_info_get_package(package_info_h package_info, char **package)
        return PACKAGE_MANAGER_ERROR_NONE;
 }
 
+API int package_info_get_main_app_id(package_info_h package_info, char **main_app_id)
+{
+       char *mainappid_dup;
+       char *pkg_info_value;
+
+       if (package_info == NULL || main_app_id == NULL)
+               return package_manager_error(PACKAGE_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+       if (pkgmgrinfo_pkginfo_get_mainappid(package_info->pkgmgr_pkginfo, &pkg_info_value) != PKGMGR_R_OK)
+               return package_manager_error(PACKAGE_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
+
+       mainappid_dup = strdup(pkg_info_value);
+       if (mainappid_dup == NULL)
+               return package_manager_error(PACKAGE_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
+
+       *main_app_id = mainappid_dup;
+
+       return PACKAGE_MANAGER_ERROR_NONE;
+}
+
 API int package_info_get_label(package_info_h package_info, char **label)
 {
        char *pkg_info_value = NULL;