From 105b7d085ad3aaccd027627470b043c81d3f737c Mon Sep 17 00:00:00 2001 From: "sooyeon.kim" Date: Thu, 27 Feb 2020 15:12:33 +0900 Subject: [PATCH] Add a logic to check screen reader vconfkey in tts_add_text() Change-Id: I1722e6a009e023fa799b6fe31d61ce84b953456e Signed-off-by: sooyeon.kim (cherry picked from commit 18a0e973c5879576ac68811b7816972ab8a71b0f) --- client/tts.c | 203 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 159 insertions(+), 44 deletions(-) diff --git a/client/tts.c b/client/tts.c index 1637606..782052e 100644 --- a/client/tts.c +++ b/client/tts.c @@ -60,7 +60,7 @@ static pthread_mutex_t g_pkgmgr_mutex = PTHREAD_MUTEX_INITIALIZER; static Eina_Bool __tts_notify_state_changed(void *data); static Eina_Bool __tts_notify_error(void *data); int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg); - +int __tts_recheck_screen_reader(); const char* tts_tag() { @@ -435,20 +435,19 @@ int tts_destroy(tts_h tts) int ret = -1; int count = 0; - int screen_reader = -1; /* check state */ switch (client->current_state) { case TTS_STATE_PAUSED: case TTS_STATE_PLAYING: case TTS_STATE_READY: - ret = vconf_get_bool(TTS_ACCESSIBILITY_KEY, &screen_reader); + ret = __tts_recheck_screen_reader(); if (0 != ret) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get screen reader"); - } else { - SLOG(LOG_INFO, tts_tag(), "[INFO] Success to get screen reader(%d), g_screen_reader(%s), client->mode(%d)", screen_reader, (true == g_screen_reader) ? "True" : "False", client->mode); - g_screen_reader = (bool)screen_reader; + SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get screen reader(%d)", ret); } + + SLOG(LOG_INFO, tts_tag(), "[INFO] g_screen_reader(%s), client->mode(%d)", (true == g_screen_reader) ? "True" : "False", client->mode); + if (!(false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode)) { do { ret = tts_dbus_request_finalize(client->uid); @@ -571,13 +570,11 @@ int tts_set_mode(tts_h tts, tts_mode_e mode) if (TTS_MODE_SCREEN_READER == mode) { int ret; - int screen_reader; - ret = vconf_get_bool(TTS_ACCESSIBILITY_KEY, &screen_reader); + ret = __tts_recheck_screen_reader(); if (0 != ret) { - SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to get screen reader"); + SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to get screen reader(%d)", ret); return TTS_ERROR_OPERATION_FAILED; } - g_screen_reader = (bool)screen_reader; tts_config_set_screen_reader_callback(client->uid, __tts_screen_reader_changed_cb); } else { tts_config_unset_screen_reader_callback(client->uid); @@ -1063,16 +1060,14 @@ int tts_unprepare(tts_h tts) int ret = -1; int count = 0; - int screen_reader = -1; - ret = vconf_get_bool(TTS_ACCESSIBILITY_KEY, &screen_reader); + ret = __tts_recheck_screen_reader(); if (0 != ret) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get screen reader"); - } else { - SLOG(LOG_INFO, tts_tag(), "[INFO] Success to get screen reader(%d), g_screen_reader(%s), client->mode(%d)", screen_reader, (true == g_screen_reader) ? "True" : "False", client->mode); - g_screen_reader = (bool)screen_reader; + SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get screen reader(%d)", ret); } + SLOG(LOG_INFO, tts_tag(), "[INFO] g_screen_reader(%s), client->mode(%d)", (true == g_screen_reader) ? "True" : "False", client->mode); + bool is_prepared = false; if (!(false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode)) { do { @@ -1351,6 +1346,25 @@ int tts_get_error_message(tts_h tts, char** err_msg) return TTS_ERROR_NONE; } +int __tts_recheck_screen_reader() +{ + SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Check screen reader again"); + + int ret = -1; + int screen_reader = 0; + + ret = vconf_get_bool(TTS_ACCESSIBILITY_KEY, &screen_reader); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret); + return TTS_ERROR_INVALID_STATE; + } else { + SLOG(LOG_INFO, TAG_TTSC, "[INFO] Current screen reader status(%d)", screen_reader); + g_screen_reader = (bool)screen_reader; + } + + return TTS_ERROR_NONE; +} + int tts_add_text(tts_h tts, const char* text, const char* language, int voice_type, int speed, int* utt_id) { SLOG(LOG_ERROR, TAG_TTSC, "[INFO] Add text: text(%s), language(%s), type(%d)", (NULL == text) ? "NULL" : text, (NULL == language) ? "NULL" : language, voice_type); @@ -1371,6 +1385,8 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Add text"); + int ret = -1; + if (NULL == tts || NULL == utt_id) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null"); SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); @@ -1421,8 +1437,17 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty } if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) { - SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request"); - return TTS_ERROR_INVALID_STATE; + /* check screen reader option one more time */ + ret = __tts_recheck_screen_reader(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret); + return TTS_ERROR_INVALID_STATE; + } else { + if (false == g_screen_reader) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available."); + return TTS_ERROR_INVALID_STATE; + } + } } if (true == client->credential_needed && NULL == client->credential) { @@ -1485,7 +1510,7 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty } /* do request */ - int ret = -1; + ret = -1; int count = 0; bool is_prepared = false; while (0 != ret) { @@ -1618,8 +1643,18 @@ int tts_play_async(tts_h tts) } if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) { - SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request"); - return TTS_ERROR_INVALID_STATE; + /* check screen reader vconf one more time */ + int ret = -1; + ret = __tts_recheck_screen_reader(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret); + return TTS_ERROR_INVALID_STATE; + } else { + if (false == g_screen_reader) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available."); + return TTS_ERROR_INVALID_STATE; + } + } } if (true == client->credential_needed && NULL == client->credential) { @@ -1642,6 +1677,8 @@ int tts_play(tts_h tts) SLOG(LOG_INFO, TAG_TTSC, "@@@ Play tts"); + int ret = -1; + if (NULL == tts) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null."); SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); @@ -1663,8 +1700,17 @@ int tts_play(tts_h tts) } if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) { - SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request"); - return TTS_ERROR_INVALID_STATE; + /* check screen reader option one more time */ + ret = __tts_recheck_screen_reader(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret); + return TTS_ERROR_INVALID_STATE; + } else { + if (false == g_screen_reader) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available."); + return TTS_ERROR_INVALID_STATE; + } + } } if (true == client->credential_needed && NULL == client->credential) { @@ -1672,7 +1718,7 @@ int tts_play(tts_h tts) return TTS_ERROR_PERMISSION_DENIED; } - int ret = -1; + ret = -1; int count = 0; bool is_prepared = false; while (0 != ret) { @@ -1807,8 +1853,17 @@ int tts_stop_aync(tts_h tts) } if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) { - SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request"); - return TTS_ERROR_INVALID_STATE; + /* check screen reader option one more time */ + int ret = __tts_recheck_screen_reader(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret); + return TTS_ERROR_INVALID_STATE; + } else { + if (false == g_screen_reader) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available."); + return TTS_ERROR_INVALID_STATE; + } + } } ecore_main_loop_thread_safe_call_async(__tts_stop_async, (void*)tts); @@ -1826,6 +1881,8 @@ int tts_stop(tts_h tts) SLOG(LOG_INFO, TAG_TTSC, "@@@ Stop tts"); + int ret = -1; + if (NULL == tts) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null"); SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); @@ -1846,11 +1903,20 @@ int tts_stop(tts_h tts) } if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) { - SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request"); - return TTS_ERROR_INVALID_STATE; + /* check screen reader option one more time */ + ret = __tts_recheck_screen_reader(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret); + return TTS_ERROR_INVALID_STATE; + } else { + if (false == g_screen_reader) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available."); + return TTS_ERROR_INVALID_STATE; + } + } } - int ret = -1; + ret = -1; int count = 0; bool is_prepared = false; while (0 != ret) { @@ -1986,8 +2052,17 @@ int tts_pause_async(tts_h tts) } if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) { - SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request"); - return TTS_ERROR_INVALID_STATE; + /* check screen reader option one more time */ + int ret = __tts_recheck_screen_reader(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret); + return TTS_ERROR_INVALID_STATE; + } else { + if (false == g_screen_reader) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available."); + return TTS_ERROR_INVALID_STATE; + } + } } ecore_main_loop_thread_safe_call_async(__tts_pause_async, (void*)tts); @@ -2005,6 +2080,8 @@ int tts_pause(tts_h tts) SLOG(LOG_INFO, TAG_TTSC, "@@@ Pause tts"); + int ret = -1; + if (NULL == tts) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null"); SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); @@ -2026,11 +2103,19 @@ int tts_pause(tts_h tts) } if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) { - SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request"); - return TTS_ERROR_INVALID_STATE; + ret = __tts_recheck_screen_reader(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret); + return TTS_ERROR_INVALID_STATE; + } else { + if (false == g_screen_reader) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available."); + return TTS_ERROR_INVALID_STATE; + } + } } - int ret = -1; + ret = -1; int count = 0; bool is_prepared = false; while (0 != ret) { @@ -2855,6 +2940,8 @@ int tts_add_pcm(tts_h tts, int event, const void* data, unsigned int data_size, SLOG(LOG_INFO, TAG_TTSC, "@@@ Add pcm tts"); + int ret = -1; + if (NULL == tts) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null."); SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); @@ -2875,11 +2962,19 @@ int tts_add_pcm(tts_h tts, int event, const void* data, unsigned int data_size, } if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) { - SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request"); - return TTS_ERROR_INVALID_STATE; + ret = __tts_recheck_screen_reader(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret); + return TTS_ERROR_INVALID_STATE; + } else { + if (false == g_screen_reader) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available."); + return TTS_ERROR_INVALID_STATE; + } + } } - int ret = -1; + ret = -1; int count = 0; bool is_prepared = false; while (0 != ret) { @@ -2919,6 +3014,8 @@ int tts_play_pcm(tts_h tts) SLOG(LOG_INFO, TAG_TTSC, "@@@ Play pcm tts"); + int ret = -1; + if (NULL == tts) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null."); SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); @@ -2939,11 +3036,19 @@ int tts_play_pcm(tts_h tts) } if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) { - SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request"); - return TTS_ERROR_INVALID_STATE; + ret = __tts_recheck_screen_reader(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret); + return TTS_ERROR_INVALID_STATE; + } else { + if (false == g_screen_reader) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available."); + return TTS_ERROR_INVALID_STATE; + } + } } - int ret = -1; + ret = -1; int count = 0; bool is_prepared = false; while (0 != ret) { @@ -2993,6 +3098,8 @@ int tts_stop_pcm(tts_h tts) SLOG(LOG_INFO, TAG_TTSC, "@@@ Stop pcm tts"); + int ret = -1; + if (NULL == tts) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null."); SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); @@ -3013,11 +3120,19 @@ int tts_stop_pcm(tts_h tts) } if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) { - SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request"); - return TTS_ERROR_INVALID_STATE; + ret = __tts_recheck_screen_reader(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret); + return TTS_ERROR_INVALID_STATE; + } else { + if (false == g_screen_reader) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available."); + return TTS_ERROR_INVALID_STATE; + } + } } - int ret = -1; + ret = -1; int count = 0; bool is_prepared = false; while (0 != ret) { -- 2.7.4