Add to set audio handles as NULL 45/241445/2 accepted/tizen/unified/20200824.134459 submit/tizen/20200821.113338
authorsooyeon.kim <sooyeon.kim@samsung.com>
Thu, 20 Aug 2020 07:52:36 +0000 (16:52 +0900)
committersooyeon.kim <sooyeon.kim@samsung.com>
Fri, 21 Aug 2020 05:31:07 +0000 (14:31 +0900)
- Fix crash in __pkgmgr_status_cb
- Add a timer handle to notify error

Change-Id: Ie74e81db928273e88d81dd1a901eef6ee1e99852
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
client/tts.c
server/ttsd_player.c

index 46bca01..b1fabc3 100644 (file)
@@ -40,6 +40,7 @@ static bool g_err_callback_status = false;
 static int g_max_text_size = -1;
 
 static Ecore_Timer* g_check_state_timer = NULL;
+static Ecore_Timer* g_notify_error_timer = NULL;
 
 /* for repetition */
 static char* g_language = NULL;
@@ -272,13 +273,20 @@ void __tts_unset_all_callbacks(tts_h tts)
 
 static int __pkgmgr_status_cb(uid_t target_uid, int req_id, const char *type, const char *pkgname, const char *key, const char *val, const void *pmsg, void *data)
 {
+       // type (the type of the pkgname)
        SLOG(LOG_INFO, TAG_TTSC, "[INFO] pkgmgr status cb is invoked. pkgname(%s), type(%s), key(%s), val(%s)", pkgname, type, key, val);
 
+       if (NULL == g_engine_name) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] engine name is NULL");
+               return 0;
+       }
+
        if (0 != strncmp(g_engine_name, pkgname, strlen(g_engine_name))) {
                SLOG(LOG_DEBUG, TAG_TTSC, "[WARN] this is not tts engine");
                return 0;
        } else {
-               if (key && 0 == strncmp(key, "start", strlen(key))) {
+               if (key) {
+                       if (0 == strncmp(key, "start", strlen(key))) {
                        if (NULL != g_pkgmgr_status) {
                                free(g_pkgmgr_status);
                                g_pkgmgr_status = NULL;
@@ -293,9 +301,17 @@ static int __pkgmgr_status_cb(uid_t target_uid, int req_id, const char *type, co
                                g_engine_update_status = 1;
                        }
                        }
-               } else if (key && 0 == strncmp(g_pkgmgr_status, "install", strlen(g_pkgmgr_status)) && 0 == strncmp(key, "end", strlen(key))) {
+                       } else if (0 == strncmp(key, "end", strlen(key)) && val && 0 == strncmp(val, "ok", strlen(val))) {
+                               if (g_pkgmgr_status) {
+                                       if (0 == strncmp(g_pkgmgr_status, "install", strlen(g_pkgmgr_status)) || 0 == strncmp(g_pkgmgr_status, "update", strlen(g_pkgmgr_status))) {
                        SLOG(LOG_ERROR, TAG_TTSC, "[INFO] finish to install");
                        g_engine_update_status = 0;
+
+                                               free(g_pkgmgr_status);
+                                               g_pkgmgr_status = NULL;
+                                       }
+                               }
+                       }
                }
        }
 
@@ -674,6 +690,11 @@ int tts_destroy(tts_h tts)
                ecore_timer_del(g_check_state_timer);
                g_check_state_timer = NULL;
        }
+       /* Delete error timer before destroying handle */
+       if (NULL != g_notify_error_timer) {
+               ecore_timer_del(g_notify_error_timer);
+               g_notify_error_timer = NULL;
+       }
 
        tts = NULL;
 
@@ -958,7 +979,12 @@ static Eina_Bool __tts_connect_daemon(void *data)
                client->reason = TTS_ERROR_ENGINE_NOT_FOUND;
                client->utt_id = -1;
 
-               ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
+               if (NULL != g_notify_error_timer) {
+                       ecore_timer_del(g_notify_error_timer);
+                       g_notify_error_timer = NULL;
+               }
+               g_notify_error_timer =  ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
+
                if (client->conn_timer) {
                        ecore_timer_del(client->conn_timer);
                        client->conn_timer = NULL;
@@ -971,7 +997,12 @@ static Eina_Bool __tts_connect_daemon(void *data)
                client->reason = TTS_ERROR_PERMISSION_DENIED;
                client->utt_id = -1;
 
-               ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
+               if (NULL != g_notify_error_timer) {
+                       ecore_timer_del(g_notify_error_timer);
+                       g_notify_error_timer = NULL;
+               }
+               g_notify_error_timer = ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
+
                if (client->conn_timer) {
                        ecore_timer_del(client->conn_timer);
                        client->conn_timer = NULL;
@@ -1040,7 +1071,12 @@ int __tts_cb_hello(int uid, int ret, int credential_needed)
                client->reason = TTS_ERROR_ENGINE_NOT_FOUND;
                client->utt_id = -1;
 
-               ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
+               if (NULL != g_notify_error_timer) {
+                       ecore_timer_del(g_notify_error_timer);
+                       g_notify_error_timer = NULL;
+               }
+               g_notify_error_timer = ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
+
                return TTS_ERROR_OPERATION_FAILED;
 
        } else if (TTS_ERROR_PERMISSION_DENIED == ret) {
@@ -1049,7 +1085,12 @@ int __tts_cb_hello(int uid, int ret, int credential_needed)
                client->reason = TTS_ERROR_PERMISSION_DENIED;
                client->utt_id = -1;
 
-               ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
+               if (NULL != g_notify_error_timer) {
+                       ecore_timer_del(g_notify_error_timer);
+                       g_notify_error_timer = NULL;
+               }
+               g_notify_error_timer = ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
+
                return TTS_ERROR_PERMISSION_DENIED;
 
        } else if (TTS_ERROR_NONE != ret) {
@@ -1067,7 +1108,11 @@ int __tts_cb_hello(int uid, int ret, int credential_needed)
        client->before_state = client->current_state;
        client->current_state = TTS_STATE_READY;
 
-       ecore_timer_add(0.0, __tts_notify_state_changed, client->tts);
+       if (NULL != g_check_state_timer) {
+               ecore_timer_del(g_check_state_timer);
+               g_check_state_timer = NULL;
+       }
+       g_check_state_timer = ecore_timer_add(0.0, __tts_notify_state_changed, client->tts);
 
        SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
        return TTS_ERROR_NONE;
@@ -1834,7 +1879,11 @@ static void __tts_play_async(void *data)
                client->reason = ret;
                client->utt_id = -1;
 
-               ecore_timer_add(0, __tts_notify_error, client->tts);
+               if (NULL != g_notify_error_timer) {
+                       ecore_timer_del(g_notify_error_timer);
+                       g_notify_error_timer = NULL;
+               }
+               g_notify_error_timer = ecore_timer_add(0, __tts_notify_error, client->tts);
                return;
        }
 
@@ -2044,7 +2093,11 @@ static void __tts_stop_async(void *data)
                client->reason = ret;
                client->utt_id = -1;
 
-               ecore_timer_add(0, __tts_notify_error, client->tts);
+               if (NULL != g_notify_error_timer) {
+                       ecore_timer_del(g_notify_error_timer);
+                       g_notify_error_timer = NULL;
+               }
+               g_notify_error_timer = ecore_timer_add(0, __tts_notify_error, client->tts);
                return;
        }
 
@@ -2242,7 +2295,11 @@ static void __tts_pause_async(void *data)
                client->reason = ret;
                client->utt_id = -1;
 
-               ecore_timer_add(0, __tts_notify_error, client->tts);
+               if (NULL != g_notify_error_timer) {
+                       ecore_timer_del(g_notify_error_timer);
+                       g_notify_error_timer = NULL;
+               }
+               g_notify_error_timer = ecore_timer_add(0, __tts_notify_error, client->tts);
                return;
        }
 
@@ -2545,6 +2602,7 @@ static Eina_Bool __tts_notify_error(void *data)
        /* check handle */
        if (NULL == client) {
                SLOG(LOG_WARN, TAG_TTSC, "Fail to notify error msg : A handle is not valid");
+               g_notify_error_timer = NULL;
                return EINA_FALSE;
        }
 
@@ -2561,6 +2619,8 @@ static Eina_Bool __tts_notify_error(void *data)
                SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
        }
 
+       g_notify_error_timer = NULL;
+
        return EINA_FALSE;
 }
 
@@ -2670,7 +2730,11 @@ int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg)
 
                                /* call callback function */
                                if (NULL != data->error_cb) {
-                                       ecore_timer_add(0, __tts_notify_error, data->tts);
+                                       if (NULL != g_notify_error_timer) {
+                                               ecore_timer_del(g_notify_error_timer);
+                                               g_notify_error_timer = NULL;
+                                       }
+                                       g_notify_error_timer = ecore_timer_add(0, __tts_notify_error, data->tts);
                                } else {
                                        SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
                                }
@@ -2718,7 +2782,11 @@ int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg)
 
                /* call callback function */
                if (NULL != client->error_cb) {
-                       ecore_timer_add(0, __tts_notify_error, client->tts);
+                       if (NULL != g_notify_error_timer) {
+                               ecore_timer_del(g_notify_error_timer);
+                               g_notify_error_timer = NULL;
+                       }
+                       g_notify_error_timer = ecore_timer_add(0, __tts_notify_error, client->tts);
                } else {
                        SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
                }
index 6895f25..282a71e 100644 (file)
@@ -93,7 +93,7 @@ static bool g_is_set_policy;
 
 #define SND_MGR_DUCKING_DURATION 500
 
-static int g_focus_watch_id;
+static int g_focus_watch_id = -1;
 
 static double g_bg_volume_ratio;
 
@@ -975,6 +975,7 @@ int ttsd_player_init()
        if (SOUND_MANAGER_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to add sound focus watch callback");
                sound_manager_destroy_stream_information(g_stream_info_h);
+               g_stream_info_h = NULL;
                return -1;
        } else {
                SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Add sound focus watch callback");
@@ -993,6 +994,9 @@ int ttsd_player_init()
        if (0 != ret) {
                sound_manager_destroy_stream_information(g_stream_info_h);
                sound_manager_remove_focus_state_watch_cb(g_focus_watch_id);
+               g_stream_info_h = NULL;
+               g_focus_watch_id = -1;
+
                return -1;
        }
 
@@ -1101,6 +1105,9 @@ int ttsd_player_release(void)
        g_playing_info = NULL;
        g_player_init = false;
 
+       g_stream_info_h = NULL;
+       g_focus_watch_id = -1;
+
        return 0;
 }