change privilege about vc_tts APIs 90/286190/1
authordyamy-lee <dyamy.lee@samsung.com>
Wed, 7 Dec 2022 12:02:18 +0000 (21:02 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Fri, 30 Dec 2022 02:13:07 +0000 (11:13 +0900)
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
common/vc_defs.h
tests/org.tizen.vc-unittests.xml

index 2c66096..afb3334 100644 (file)
@@ -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;
 
index 1fb53d3..d6ad568 100644 (file)
@@ -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
index 8c69747..d696b69 100644 (file)
@@ -11,6 +11,7 @@
         <privileges>
             <privilege>http://tizen.org/privilege/recorder</privilege>
             <privilege>http://tizen.org/privilege/voicecontrol.manager</privilege>
+            <privilege>http://tizen.org/privilege/voicecontrol.tts</privilege>
             <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
             <privilege>http://tizen.org/privilege/appmanager.kill</privilege>
             <privilege>http://tizen.org/privilege/datasharing</privilege>