From cd8a2ebff736db5e568717f612d0402f5dcc5440 Mon Sep 17 00:00:00 2001 From: Yunjin Lee Date: Fri, 9 Mar 2018 14:33:51 +0900 Subject: [PATCH] Add privacy feature and deprecate redundant API - Add privacy feature to distinguish profiles that are not supporting privacy feature - Add error enum PRVINFO_ERROR_NOT_SUPPORTED - Deprecate privilege_info_get_privacy_privilege_status() since the same function is provided at privacy_privilege_manager(ppm_check_permission()). Change-Id: Ica1cd1eef95f9ff00f951bc96f50b5d45b90c4cb Signed-off-by: Yunjin Lee --- doc/privilege-info_doc.h | 8 ++++++++ packaging/privilege-info.spec | 3 ++- src/CMakeLists.txt | 2 +- src/include/privilege_information.h | 6 +++++- src/privilege_info.c | 35 ++++++++++++++++++++++++++++++++++- test/tc_privilege_info.c | 2 ++ 6 files changed, 52 insertions(+), 4 deletions(-) diff --git a/doc/privilege-info_doc.h b/doc/privilege-info_doc.h index d65741a..816e384 100755 --- a/doc/privilege-info_doc.h +++ b/doc/privilege-info_doc.h @@ -29,6 +29,14 @@ * A library for reading privilege information of the given privilege and API issue version. * It provides the display name or description of privileges. * If there's no matching privilege then it shows last token of given privilege or description string for undefined privileges. + * + * @section CAPI_SECURITY_FRAMEWORK_PRIVILEGE_INFO_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/security.privacy_privilege\n + * It is recommended to design feature related codes in your application for reliability.\n + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * More details on featuring your application can be found from Feature Element. */ diff --git a/packaging/privilege-info.spec b/packaging/privilege-info.spec index 2c9c646..b23542c 100644 --- a/packaging/privilege-info.spec +++ b/packaging/privilege-info.spec @@ -1,6 +1,6 @@ Name: privilege-info Summary: Privilege Information -Version: 0.0.1 +Version: 0.0.2 Release: 1 Group: Security/API License: Apache-2.0 @@ -17,6 +17,7 @@ BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(cynara-session) BuildRequires: pkgconfig(libsmack) BuildRequires: pkgconfig(libtzplatform-config) +BuildRequires: pkgconfig(capi-system-info) %description Provides Privilege Information(Privilege Info) API diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9ef2023..2103600 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,7 +8,7 @@ SET(PRIV_INFO_SOURCES INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include) -SET(requires glib-2.0 dlog security-privilege-manager cynara-client cynara-session libsmack) +SET(requires glib-2.0 dlog security-privilege-manager cynara-client cynara-session libsmack capi-system-info) INCLUDE(FindPkgConfig) pkg_check_modules(${PACKAGE_NAME} REQUIRED ${requires}) FOREACH(flag ${${PACKAGE_NAME}_CFLAGS}) diff --git a/src/include/privilege_information.h b/src/include/privilege_information.h index b6c47af..fbfad92 100755 --- a/src/include/privilege_information.h +++ b/src/include/privilege_information.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014-2018 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. @@ -42,6 +42,7 @@ typedef enum { PRVINFO_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid function parameter */ PRVINFO_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ PRVINFO_ERROR_INTERNAL_ERROR = TIZEN_ERROR_UNKNOWN, /**< Unknown error */ + PRVINFO_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED /**< Not supported (Since 5.0) */ } privilege_info_error_e; @@ -130,11 +131,13 @@ int privilege_info_get_description_by_pkgtype(const char *package_type, const ch * @retval #PRVINFO_ERROR_OUT_OF_MEMORY Out of memory * @retval #PRVINFO_ERROR_INVALID_PARAMETER Invalid function parameter * @retval #PRVINFO_ERROR_INTERNAL_ERROR Unknown error + * @retval #PRVINFO_ERROR_NOT_SUPPORTED Not supported */ int privilege_info_get_privacy_display_name(const char *privilege, char **privacy_name); /** + * @deprecated Deprecated since 5.0. Use ppm_check_permission() instead. You can refer to @ref CAPI_PRIVACY_PRIVILEGE_MANAGER_MODULE. * @brief Gets the status of the given privacy related privilege. * @since_tizen 3.0 * @remarks @a privilege must be privacy related, otherwise #PRVINFO_ERROR_INVALID_PARAMETER is returned. @@ -147,6 +150,7 @@ int privilege_info_get_privacy_display_name(const char *privilege, char **privac * @retval #PRVINFO_ERROR_NONE Successful * @retval #PRVINFO_ERROR_INVALID_PARAMETER Invalid function parameter * @retval #PRVINFO_ERROR_INTERNAL_ERROR Unknown error + * @retval #PRVINFO_ERROR_NOT_SUPPORTED Not supported */ int privilege_info_get_privacy_privilege_status(const char *privilege, bool *status); diff --git a/src/privilege_info.c b/src/privilege_info.c index a300b00..79b2ea7 100755 --- a/src/privilege_info.c +++ b/src/privilege_info.c @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2014-2018 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. + */ + #include #include #include @@ -7,12 +23,28 @@ #include #include #include +#include #include "privilege_information.h" #ifdef LOG_TAG #undef LOG_TAG #define LOG_TAG "PRIVILEGE_INFO" #endif +#define PRIVACY_FEATURE "http://tizen.org/feature/security.privacy_privilege" +#define CHECK_FEATURE_SUPPORTED(feature_name) \ + do { \ + bool is_supported = false; \ + int ret = system_info_get_platform_bool(feature_name, &is_supported); \ + if (ret != SYSTEM_INFO_ERROR_NONE) { \ + LOGE("system_info_get_platform_bool failed. ret = %d", ret); \ + return PRVINFO_ERROR_INTERNAL_ERROR; \ + } \ + if (!is_supported) { \ + LOGE("%s is disabled", feature_name); \ + return PRVINFO_ERROR_NOT_SUPPORTED; \ + } \ + } while (0) + #define UIDMAXLEN 10 #define TryReturn(condition, expr, returnValue, ...) \ @@ -235,6 +267,7 @@ int privilege_info_get_description_by_pkgtype(const char *package_type, const ch PI_API int privilege_info_get_privacy_display_name(const char *privilege, char **privacy_display_name) { + CHECK_FEATURE_SUPPORTED(PRIVACY_FEATURE); TryReturn(privilege != NULL, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL"); TryReturn(privilege_db_manager_is('p', privilege) == 1, , PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege does not exist or is not a privacy related"); @@ -255,6 +288,7 @@ int privilege_info_get_privacy_display_name(const char *privilege, char **privac PI_API int privilege_info_get_privacy_privilege_status(const char *privilege, bool *status) { + CHECK_FEATURE_SUPPORTED(PRIVACY_FEATURE); TryReturn(privilege != NULL, *status = true, PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege is NULL"); TryReturn(privilege_db_manager_is('p', privilege) == 1, *status = true, PRVINFO_ERROR_INVALID_PARAMETER, "[PRVINFO_ERROR_INVALID_PARAMETER] privilege does not exist or is not a privacy related"); @@ -291,4 +325,3 @@ int privilege_info_get_privacy_privilege_status(const char *privilege, bool *sta return ret; } - diff --git a/test/tc_privilege_info.c b/test/tc_privilege_info.c index 08de15d..fb7e7c6 100755 --- a/test/tc_privilege_info.c +++ b/test/tc_privilege_info.c @@ -41,6 +41,8 @@ static const char* __get_result_string(privilege_info_error_e ret) return "PRVINFO_ERROR_OUT_OF_MEMORY"; else if (ret == PRVINFO_ERROR_INTERNAL_ERROR) return "PRVINFO_ERROR_INTERNAL_ERROR"; + else if (ret == PRVINFO_ERROR_NOT_SUPPORTED) + return "PRVINFO_ERROR_NOT_SUPPORTED"; return "PRVINFO_ERROR_NO_MATCHED_ERROR_MESSAGE"; } -- 2.7.4