From 9da9127eb9b2a0e4d06d86aa1430e55f965a9d68 Mon Sep 17 00:00:00 2001 From: dyamy-lee Date: Wed, 7 Dec 2022 21:02:18 +0900 Subject: [PATCH] change privilege about vc_tts APIs vc_tts APIs need to check voicecontrol.tts privilege. So, add checking function about voicecontrol.tts privilege and use this in vc_tts APIs. For vc_tts APIs, these don't need to check microphone, speech.control, recorder. So, no check thoses privilege Change-Id: I5d7ed88d6c2921063f7dddb7037c56bf2f814190 --- client/vc.c | 55 ++++++++++++++++++++++++++++---- common/vc_defs.h | 1 + tests/org.tizen.vc-unittests.xml | 1 + 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/client/vc.c b/client/vc.c index 2c66096..afb3334 100644 --- a/client/vc.c +++ b/client/vc.c @@ -54,6 +54,7 @@ static int g_daemon_pid = 0; static int g_feature_enabled = -1; static bool g_privilege_allowed = false; +static bool g_vc_tts_privilege_allowed = false; static bool g_backup = false; static pthread_mutex_t g_cynara_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -197,6 +198,46 @@ int __check_feature_privilege() return VC_ERROR_NONE; } +int __vc_tts_check_privilege() +{ + if (true == g_vc_tts_privilege_allowed) + return VC_ERROR_NONE; + + pthread_mutex_lock(&g_cynara_mutex); + + if (false == g_vc_tts_privilege_allowed) { + bool ret = true; + ret = __check_privilege_initialize(); + if (false == ret) { + //LCOV_EXCL_START + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] privilege initialize is failed"); + pthread_mutex_unlock(&g_cynara_mutex); + return VC_ERROR_PERMISSION_DENIED; + //LCOV_EXCL_STOP + } + + char uid[32]; + snprintf(uid, 32, "%d", getuid()); + ret = true; + ret = __check_privilege(uid, VC_TTS_PRIVILEGE); + if (false == ret) { + //LCOV_EXCL_START + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Permission is denied(%s)(%s)", VC_TTS_PRIVILEGE, uid); + __check_privilege_deinitialize(); + g_vc_tts_privilege_allowed = false; + pthread_mutex_unlock(&g_cynara_mutex); + return VC_ERROR_PERMISSION_DENIED; + //LCOV_EXCL_STOP + } + + __check_privilege_deinitialize(); + } + + g_vc_tts_privilege_allowed = true; + pthread_mutex_unlock(&g_cynara_mutex); + return VC_ERROR_NONE; +} + //LCOV_EXCL_START static const char* __vc_get_error_code(vc_error_e err) { @@ -2719,7 +2760,7 @@ int vc_tts_request(const char* text, const char* language, bool to_vc_manager, i SLOG(LOG_DEBUG, TAG_VCC, "@@@ Request tts"); - ret = __check_feature_privilege(); + ret = __vc_tts_check_privilege(); if (VC_ERROR_NONE != ret) return ret; @@ -2778,7 +2819,7 @@ int vc_tts_cancel(int utt_id) SLOG(LOG_DEBUG, TAG_VCC, "@@@ Cancel tts"); - ret = __check_feature_privilege(); + ret = __vc_tts_check_privilege(); if (VC_ERROR_NONE != ret) return ret; @@ -2842,7 +2883,7 @@ int vc_tts_get_synthesized_audio_details(int* rate, vc_audio_channel_e* channel, SLOG(LOG_DEBUG, TAG_VCC, "@@@ Get tts audio format"); - ret = __check_feature_privilege(); + ret = __vc_tts_check_privilege(); if (VC_ERROR_NONE != ret) return ret; @@ -2896,7 +2937,7 @@ int vc_tts_get_synthesized_audio_details(int* rate, vc_audio_channel_e* channel, int vc_tts_set_streaming_cb(vc_tts_streaming_cb callback, void* user_data) { int ret; - ret = __check_feature_privilege(); + ret = __vc_tts_check_privilege(); if (VC_ERROR_NONE != ret) return ret; @@ -2920,7 +2961,7 @@ int vc_tts_set_streaming_cb(vc_tts_streaming_cb callback, void* user_data) int vc_tts_unset_streaming_cb(void) { int ret; - ret = __check_feature_privilege(); + ret = __vc_tts_check_privilege(); if (VC_ERROR_NONE != ret) return ret; @@ -2959,7 +3000,7 @@ int __vc_cb_utterance_status(int utt_id, int utt_status) int vc_tts_set_utterance_status_cb(vc_tts_utterance_status_cb callback, void* user_data) { int ret; - ret = __check_feature_privilege(); + ret = __vc_tts_check_privilege(); if (VC_ERROR_NONE != ret) return ret; @@ -2982,7 +3023,7 @@ int vc_tts_set_utterance_status_cb(vc_tts_utterance_status_cb callback, void* us int vc_tts_unset_utterance_status_cb(void) { int ret; - ret = __check_feature_privilege(); + ret = __vc_tts_check_privilege(); if (VC_ERROR_NONE != ret) return ret; diff --git a/common/vc_defs.h b/common/vc_defs.h index 1fb53d3..d6ad568 100644 --- a/common/vc_defs.h +++ b/common/vc_defs.h @@ -285,6 +285,7 @@ extern "C" { #define VC_PRIVILEGE_APPMGR_LAUNCH "http://tizen.org/privilege/appmanager.launch" #define VC_PRIVILEGE_DATASHARING "http://tizen.org/privilege/datasharing" #define VC_MGR_PRIVILEGE "http://tizen.org/privilege/voicecontrol.manager" +#define VC_TTS_PRIVILEGE "http://tizen.org/privilege/voicecontrol.tts" /****************************************************************************************** * Definitions for common enum diff --git a/tests/org.tizen.vc-unittests.xml b/tests/org.tizen.vc-unittests.xml index 8c69747..d696b69 100644 --- a/tests/org.tizen.vc-unittests.xml +++ b/tests/org.tizen.vc-unittests.xml @@ -11,6 +11,7 @@ http://tizen.org/privilege/recorder http://tizen.org/privilege/voicecontrol.manager + http://tizen.org/privilege/voicecontrol.tts http://tizen.org/privilege/appmanager.launch http://tizen.org/privilege/appmanager.kill http://tizen.org/privilege/datasharing -- 2.34.1