From 78bfdad0e71474ec2b8725a947c7fd8d4f48e187 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 14 May 2020 13:49:50 +0900 Subject: [PATCH 01/16] Fix build errors Change-Id: I69e8d81808e4a7ddf984336151cfb3ea653a1765 --- packaging/org.tizen.multi-assistant-service.spec | 3 +++ plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index 6ce5be6..99398c1 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -52,6 +52,9 @@ LDFLAGS="$LDFLAGS -Wl,-z -Wl,nodelete" export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" %endif +export CFLAGS+=" -Wno-format-truncation -Wno-stringop-truncation -Wno-format-overflow -Wno-stringop-overflow" +export CXXFLAGS+=" -Wno-format-truncation -Wno-stringop-truncation -Wno-format-overflow -Wno-stringop-overflow" + export LDFLAGS %cmake \ -DCMAKE_INSTALL_PREFIX=%{_appdir} \ diff --git a/plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp b/plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp index 6e30433..461eb5b 100644 --- a/plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp +++ b/plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp @@ -229,7 +229,7 @@ int wakeup_manager_set_default_assistant(const char* appid) MWR_LOGD("[ENTER]"); if (NULL == appid) { - MWR_LOGD("[ERROR] Parameter is invalid, appid(%s)", appid); + MWR_LOGD("[ERROR] Parameter is NULL"); return -1; } @@ -261,7 +261,7 @@ int wakeup_manager_set_language(const char* language) MWR_LOGD("[ENTER]"); if (NULL == language) { - MWR_LOGD("[ERROR] Parameter is invalid, language(%s)", language); + MWR_LOGD("[ERROR] Parameter is NULL"); return -1; } @@ -307,7 +307,7 @@ int wakeup_manager_update_voice_feedback_state(const char* appid, int state) string appid_string; if (NULL == appid) { - MWR_LOGD("[ERROR] Parameter is invalid, appid(%s)", appid); + MWR_LOGD("[ERROR] Parameter is NULL"); } else { appid_string = appid; } @@ -344,7 +344,7 @@ int wakeup_manager_set_background_volume(const char* appid, double ratio) string appid_string; if (NULL == appid) { - MWR_LOGD("[ERROR] Parameter is invalid, appid(%s)", appid); + MWR_LOGD("[ERROR] Parameter is NULL"); } else { appid_string = appid; } @@ -362,7 +362,7 @@ int wakeup_manager_update_recognition_result(const char* appid, int result) string appid_string; if (NULL == appid) { - MWR_LOGD("[ERROR] Parameter is invalid, appid(%s)", appid); + MWR_LOGD("[ERROR] Parameter is NULL"); } else { appid_string = appid; } -- 2.7.4 From 2955e711f224e750830752f03e6b0c62a18f83ed Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 14 May 2020 15:32:17 +0900 Subject: [PATCH 02/16] Feed utterance audio only to the selected wakeup engine Change-Id: I0ca917128e28ab77d5a37b033ecd62ea8d0d4123 --- plugins/wakeup-manager/inc/wakeup_engine_manager.h | 1 + plugins/wakeup-manager/src/wakeup_engine_manager.cpp | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/plugins/wakeup-manager/inc/wakeup_engine_manager.h b/plugins/wakeup-manager/inc/wakeup_engine_manager.h index fb668a9..4c196eb 100644 --- a/plugins/wakeup-manager/inc/wakeup_engine_manager.h +++ b/plugins/wakeup-manager/inc/wakeup_engine_manager.h @@ -206,6 +206,7 @@ private: thread mStreamingThread; atomic_bool mStopStreamingThread{false}; + wakeup_manager_state_e mWakeupManagerState{WAKEUP_MANAGER_STATE_INACTIVE}; bool mWakeWordAudioRequired{false}; }; diff --git a/plugins/wakeup-manager/src/wakeup_engine_manager.cpp b/plugins/wakeup-manager/src/wakeup_engine_manager.cpp index aa31ab7..d9181dc 100644 --- a/plugins/wakeup-manager/src/wakeup_engine_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_engine_manager.cpp @@ -510,6 +510,7 @@ void CWakeupEngineManager::update_manager_state(wakeup_manager_state_e state) } } } + mWakeupManagerState = state; } void CWakeupEngineManager::update_recognition_result(string appid, int result) @@ -598,9 +599,19 @@ void CWakeupEngineManager::engine_feed_audio_data(long time, void* data, int len info.audio_data_require_status && info.interface.feed_audio_data) { try { - int ret = info.interface.feed_audio_data(time, data, len); - if (0 != ret) { - LOGE("[ERROR] Fail to feed speech data, ret(%d) : %s", ret, info.engine_name.c_str()); + bool filtered_out = false; + /* After a wakeup event, wakeup engines other than the selected one + does not need to receive audio data. */ + if (WAKEUP_MANAGER_STATE_UTTERANCE == mWakeupManagerState) { + if (mSelectedEngine && &info != mSelectedEngine) { + filtered_out = true; + } + } + if (!filtered_out) { + int ret = info.interface.feed_audio_data(time, data, len); + if (0 != ret) { + LOGE("[ERROR] Fail to feed speech data, ret(%d) : %s", ret, info.engine_name.c_str()); + } } } catch (const std::exception& e) { MWR_LOGE("[ERROR] wakeup engine %s threw exception : %s", -- 2.7.4 From a989fa3ec68d7c0e1c898f778a9b8ebcce26164e Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 14 May 2020 15:33:08 +0900 Subject: [PATCH 03/16] Bump version to 0.2.32 Change-Id: I623e4745dd7c1834ad961403664910a7e1198f97 --- org.tizen.multi-assistant-service.xml | 2 +- packaging/org.tizen.multi-assistant-service.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.tizen.multi-assistant-service.xml b/org.tizen.multi-assistant-service.xml index 418edad..7c451d8 100644 --- a/org.tizen.multi-assistant-service.xml +++ b/org.tizen.multi-assistant-service.xml @@ -1,5 +1,5 @@ - + Won Nam Jang Sooyeon Kim diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index 99398c1..b41d4a3 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -1,6 +1,6 @@ Name: org.tizen.multi-assistant-service Summary: Multi assistant service -Version: 0.2.31 +Version: 0.2.32 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Flora-1.1 -- 2.7.4 From 3d9c1eef9bb957f237d59ef52cb050138aca14d2 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 21 May 2020 16:49:49 +0900 Subject: [PATCH 04/16] Add log messages for checking startup process Change-Id: I79a0d20bed3ee46f81e8a6b30f6df821c5838f13 --- src/multi_assistant_service.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c index fcbd186..a449555 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.c @@ -65,6 +65,26 @@ static ma_voice_key_status_e g_last_voice_key_status = MA_VOICE_KEY_STATUS_RELEA /* client list */ static GSList* g_client_list = NULL; +#ifdef ENABLE_FILE_LOG +static void file_log(const char* s) +{ + FILE *fp = fopen("/tmp/maservice_log.txt", "a"); + if (fp) { + char time_buf[96] = {0}; + + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + const time_t tt = ts.tv_sec; + struct tm *const ptm = localtime(&tt); + + strftime(time_buf, sizeof(time_buf), "%m-%d %H:%M:%S", ptm); + fprintf(fp, "[%s] %s\n", time_buf, s); + fclose(fp); + } + fflush(fp); +} +#endif + int ma_client_create(ma_client_s *info) { if (NULL == info) { @@ -1505,8 +1525,10 @@ static void _package_manager_event_cb(const char *type, const char *package, pac bool service_app_create(void *data) { // Todo: add your code here. - - MAS_LOGD("[Enter] Service app create"); + MAS_LOGI("[ENTER] Service app create"); +#ifdef ENABLE_FILE_LOG + file_log("[ENTER] Service app create"); +#endif if (0 != init_wakeup()) { MAS_LOGE("Fail to init wakeup service"); @@ -1529,6 +1551,10 @@ bool service_app_create(void *data) } } +#ifdef ENABLE_FILE_LOG + file_log("[END] Service app create"); +#endif + MAS_LOGI("[END] Service app create"); return true; } @@ -1580,6 +1606,11 @@ service_app_low_memory(app_event_info_h event_info, void *user_data) int main(int argc, char* argv[]) { + LOGI("Main function starts"); +#ifdef ENABLE_FILE_LOG + file_log("Main function starts"); +#endif + char ad[50] = {0,}; service_app_lifecycle_callback_s event_callback; app_event_handler_h handlers[5] = {NULL, }; -- 2.7.4 From add5d3262352683c10339a1eb5cf9af47597dfda Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 25 May 2020 08:46:11 +0900 Subject: [PATCH 05/16] Use app_manager_is_running() for checking process existence Change-Id: Ibe88a55dc15f38cd43a51667fc19a1b34eabe0c8 --- src/multi_assistant_service.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c index a449555..8ae416a 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.c @@ -923,13 +923,17 @@ int mas_get_client_pid_by_appid(const char *appid) } } - int status = aul_app_get_status_bypid(ret); - if (-1 != ret && 0 > status) { - MAS_LOGE("The PID for %s was %d, but it seems to be terminated : %d", - (appid ? appid : "NULL"), ret, status); - mas_client_deinitialize(ret); - ret = -1; +#ifdef CHECK_APP_IS_RUNNING + bool running = false; + if (appid && 0 == app_manager_is_running(appid, &running)) { + if (!running) { + MAS_LOGE("The PID for %s was %d, but it seems to be terminated : %d", + (appid ? appid : "NULL"), ret, running); + mas_client_deinitialize(ret); + ret = -1; + } } +#endif return ret; } @@ -944,13 +948,17 @@ const char* mas_get_client_appid_by_pid(int pid) ret = client->appid; } - int status = aul_app_get_status_bypid(pid); - if (-1 != ret && 0 > status) { - MAS_LOGE("The appid for %d was %s, but it seems to be terminated : %d", - pid, (ret ? ret : "NULL"), status); - mas_client_deinitialize(pid); - ret = NULL; +#ifdef CHECK_APP_IS_RUNNING + bool running = false; + if (ret && 0 == app_manager_is_running(ret, &running)) { + if (!running) { + MAS_LOGE("The appid for %d was %s, but it seems to be terminated : %d", + pid, (ret ? ret : "NULL"), running); + mas_client_deinitialize(pid); + ret = NULL; + } } +#endif return ret; } -- 2.7.4 From dc9ed53e4333130b50c71ece3f16b7222056e252 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 25 May 2020 09:11:56 +0900 Subject: [PATCH 06/16] Bump version to 0.2.33 Change-Id: I10526ccabc9ffd6fb37aea844a28c95c596e9d93 --- org.tizen.multi-assistant-service.xml | 2 +- packaging/org.tizen.multi-assistant-service.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.tizen.multi-assistant-service.xml b/org.tizen.multi-assistant-service.xml index 7c451d8..4d64d60 100644 --- a/org.tizen.multi-assistant-service.xml +++ b/org.tizen.multi-assistant-service.xml @@ -1,5 +1,5 @@ - + Won Nam Jang Sooyeon Kim diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index b41d4a3..31eed78 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -1,6 +1,6 @@ Name: org.tizen.multi-assistant-service Summary: Multi assistant service -Version: 0.2.32 +Version: 0.2.33 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Flora-1.1 -- 2.7.4 From 68e0b4f06b2c39decfa3d96d3d4cda89b380ad76 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 25 May 2020 11:35:05 +0900 Subject: [PATCH 07/16] Enable app_manager_is_running and add retry logic on failure Change-Id: I3f32c7e8ef93e96b1ca57276c89748e3f11e6e4a --- src/multi_assistant_service.c | 44 +++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c index 8ae416a..6438333 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.c @@ -923,17 +923,21 @@ int mas_get_client_pid_by_appid(const char *appid) } } -#ifdef CHECK_APP_IS_RUNNING + int retry_num = 0; + bool succeeded = false; bool running = false; - if (appid && 0 == app_manager_is_running(appid, &running)) { - if (!running) { - MAS_LOGE("The PID for %s was %d, but it seems to be terminated : %d", - (appid ? appid : "NULL"), ret, running); - mas_client_deinitialize(ret); - ret = -1; - } + if (appid) { + do { + succeeded = (0 == app_manager_is_running(appid, &running)); + if (succeeded && !running) { + MAS_LOGE("The PID for %s was %d, but it seems to be terminated : %d", + (appid ? appid : "NULL"), ret, running); + mas_client_deinitialize(ret); + ret = -1; + } + if (!succeeded) usleep(10000); + } while(!succeeded && retry_num++ < 3); } -#endif return ret; } @@ -948,17 +952,21 @@ const char* mas_get_client_appid_by_pid(int pid) ret = client->appid; } -#ifdef CHECK_APP_IS_RUNNING + int retry_num = 0; + bool succeeded = false; bool running = false; - if (ret && 0 == app_manager_is_running(ret, &running)) { - if (!running) { - MAS_LOGE("The appid for %d was %s, but it seems to be terminated : %d", - pid, (ret ? ret : "NULL"), running); - mas_client_deinitialize(pid); - ret = NULL; - } + if (ret) { + do { + succeeded = (0 == app_manager_is_running(ret, &running)); + if (succeeded && !running) { + MAS_LOGE("The appid for %d was %s, but it seems to be terminated : %d", + pid, (ret ? ret : "NULL"), running); + mas_client_deinitialize(pid); + ret = NULL; + } + if (!succeeded) usleep(10000); + } while(!succeeded && retry_num++ < 3); } -#endif return ret; } -- 2.7.4 From 8703e44b952a5d8f9053fac74983b067829d9502 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 25 May 2020 12:03:24 +0900 Subject: [PATCH 08/16] Make sure uninstall completion event also restarts service Change-Id: I0349eeb25d3bf32c839c6eeb5ea566410b28e987 --- src/multi_assistant_service.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c index 6438333..9ed865e 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.c @@ -1476,6 +1476,7 @@ static void _package_manager_event_cb(const char *type, const char *package, pac pkgmgrinfo_pkginfo_h handle = NULL; static bool in_progress = false; bool should_exit = false; + bool pkginfo_found = true; if (!package || !type) return; @@ -1486,7 +1487,8 @@ static void _package_manager_event_cb(const char *type, const char *package, pac return; if (PACKAGE_MANAGER_EVENT_STATE_STARTED != event_state && - PACKAGE_MANAGER_EVENT_STATE_COMPLETED != event_state) + PACKAGE_MANAGER_EVENT_STATE_COMPLETED != event_state && + PACKAGE_MANAGER_EVENT_STATE_FAILED != event_state) return; bool user = false; @@ -1500,16 +1502,28 @@ static void _package_manager_event_cb(const char *type, const char *package, pac ret = pkgmgrinfo_pkginfo_get_usr_pkginfo (package, uid, &handle); if (ret != PMINFO_R_OK || NULL == handle) { LOGW("Failed to call pkgmgrinfo_pkginfo_get_pkginfo & get_usr_pkginfo(\"%s\",~) returned %d, uid : %d", package, ret, getuid ()); - return; + pkginfo_found = false; } } - if (user) { - /* Try to get in user packages */ - pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, pkg_app_list_cb, (void *)&ret, uid); - } else { - /* Try to get in global packages */ - pkgmgrinfo_appinfo_get_list(handle, PMINFO_ALL_APP, pkg_app_list_cb, (void *)&ret); + if (pkginfo_found) { + if (user) { + /* Try to get in user packages */ + pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, pkg_app_list_cb, (void *)&ret, uid); + } else { + /* Try to get in global packages */ + pkgmgrinfo_appinfo_get_list(handle, PMINFO_ALL_APP, pkg_app_list_cb, (void *)&ret); + } + } else { + /* Even if we failed acquiring the pkginfo, proceed if we're uninstalling + since at the time of uninstall completion, pkginfo would not exist */ + if (in_progress) { + if (PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL == event_type && + (PACKAGE_MANAGER_EVENT_STATE_COMPLETED == event_state || + PACKAGE_MANAGER_EVENT_STATE_FAILED == event_state)) { + ret = 1; + } + } } if (1 == ret) { if (PACKAGE_MANAGER_EVENT_STATE_STARTED == event_state) { @@ -1518,8 +1532,10 @@ static void _package_manager_event_cb(const char *type, const char *package, pac in_progress = true; deinit_plugin(); } - } else if (PACKAGE_MANAGER_EVENT_STATE_COMPLETED == event_state) { - LOGI("processing PACKAGE_MANAGER_EVENT_STATE_COMPLETED event : %d", event_type); + } else if (PACKAGE_MANAGER_EVENT_STATE_COMPLETED == event_state || + PACKAGE_MANAGER_EVENT_STATE_FAILED == event_state) { + LOGI("processing PACKAGE_MANAGER_EVENT_STATE_COMPLETED/FAILED event : %d %d", + event_state, event_type); if (false == in_progress) { deinit_plugin(); } @@ -1528,7 +1544,7 @@ static void _package_manager_event_cb(const char *type, const char *package, pac } } - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + if (handle) pkgmgrinfo_pkginfo_destroy_pkginfo(handle); if (should_exit) { LOGI("Now restarting multi-assistant-service for reloading updated modules"); -- 2.7.4 From 8a540b3b1022845c79abc1dd336e24fece7f22e0 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Wed, 27 May 2020 13:35:16 +0900 Subject: [PATCH 09/16] Bump version to 0.2.34 Change-Id: I63ad89fe501034375b402916d6ec1ae36fdcaa3c --- org.tizen.multi-assistant-service.xml | 2 +- packaging/org.tizen.multi-assistant-service.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.tizen.multi-assistant-service.xml b/org.tizen.multi-assistant-service.xml index 4d64d60..db96b45 100644 --- a/org.tizen.multi-assistant-service.xml +++ b/org.tizen.multi-assistant-service.xml @@ -1,5 +1,5 @@ - + Won Nam Jang Sooyeon Kim diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index 31eed78..f5ffa24 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -1,6 +1,6 @@ Name: org.tizen.multi-assistant-service Summary: Multi assistant service -Version: 0.2.33 +Version: 0.2.34 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Flora-1.1 -- 2.7.4 From 9549b5c5b81aa3be186cac1e7caabd05e34c5504 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Fri, 17 Jul 2020 14:30:26 +0900 Subject: [PATCH 10/16] Use async version of aul_launch_app for avoiding deadlock Change-Id: I484ced8492df92262ee34e19b687ae62d4cba76f --- src/multi_assistant_service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c index 9ed865e..3fc3b00 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.c @@ -1184,9 +1184,9 @@ int mas_bring_client_to_foreground(const char* appid) return -1; } - int result = aul_launch_app(appid, b); + int result = aul_launch_app_async(appid, b); if (result < AUL_R_OK) { - MAS_LOGE("ERROR : aul_launch_app failed. app_id [%s] bundle[%p] result[%d : %s]", + MAS_LOGE("ERROR : aul_launch_app_async failed. app_id [%s] bundle[%p] result[%d : %s]", appid, b, result, get_error_message(result)); } -- 2.7.4 From 39ee9688098e5e7f79fe5d510373fed1c6446152 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Fri, 17 Jul 2020 11:42:04 +0900 Subject: [PATCH 11/16] Bump version to 0.2.35 Change-Id: Ib8b1ca66b5e49ef6266973cb960092c7839473a3 --- org.tizen.multi-assistant-service.xml | 2 +- packaging/org.tizen.multi-assistant-service.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.tizen.multi-assistant-service.xml b/org.tizen.multi-assistant-service.xml index db96b45..c012fe7 100644 --- a/org.tizen.multi-assistant-service.xml +++ b/org.tizen.multi-assistant-service.xml @@ -1,5 +1,5 @@ - + Won Nam Jang Sooyeon Kim diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index f5ffa24..5288e81 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -1,6 +1,6 @@ Name: org.tizen.multi-assistant-service Summary: Multi assistant service -Version: 0.2.34 +Version: 0.2.35 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Flora-1.1 -- 2.7.4 From f9124a7b3ddf502a0cdfd8f132ff3bf4109cdf22 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Wed, 8 Jul 2020 21:27:34 +0900 Subject: [PATCH 12/16] Fix streaming START/FINISH event pair mismatch Change-Id: I03680aa7848579ac5fd1235f264d5c74d7bc3876 --- plugins/wakeup-manager/inc/wakeup_manager.h | 6 ++ plugins/wakeup-manager/src/wakeup_manager.cpp | 101 ++++++++++++--------- .../wakeup-manager/src/wakeup_policy_default.cpp | 2 + 3 files changed, 66 insertions(+), 43 deletions(-) diff --git a/plugins/wakeup-manager/inc/wakeup_manager.h b/plugins/wakeup-manager/inc/wakeup_manager.h index de7cb11..437dc06 100644 --- a/plugins/wakeup-manager/inc/wakeup_manager.h +++ b/plugins/wakeup-manager/inc/wakeup_manager.h @@ -136,6 +136,12 @@ public: void feed_audio_data(mas_speech_streaming_event_e event, void* buffer, int len); void set_dependency_module_command(string engine_name, string command); + + void start_streaming_duration_timer(); + void stop_streaming_duration_timer(); + + void set_streaming_duration_timer(Ecore_Timer* timer); + Ecore_Timer* get_streaming_duration_timer(); private: bool change_voice_key_status(ma_voice_key_status_e status); diff --git a/plugins/wakeup-manager/src/wakeup_manager.cpp b/plugins/wakeup-manager/src/wakeup_manager.cpp index b0ddfd1..1df79ea 100644 --- a/plugins/wakeup-manager/src/wakeup_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_manager.cpp @@ -137,10 +137,7 @@ bool CWakeupManager::deinitialize() { MWR_LOGI("[ENTER]"); - if (mStreamingDurationTimer) { - ecore_timer_del(mStreamingDurationTimer); - mStreamingDurationTimer = nullptr; - } + stop_streaming_duration_timer(); dependency_resolver_deinitialize(); @@ -562,6 +559,7 @@ bool CWakeupManager::process_plugin_event(mas_plugin_event_e event, void* data, } } if (stop_recording) { + stop_streaming_duration_timer(); mAudioManager.finalize_audio_data(); if (STREAMING_MODE::UTTERANCE == mStreamingMode) { @@ -603,6 +601,8 @@ static Eina_Bool streaming_duration_expired(void *data) CWakeupManager *wakeup_manager = static_cast(data); if (nullptr == wakeup_manager) return ECORE_CALLBACK_CANCEL; + wakeup_manager->set_streaming_duration_timer(nullptr); + CAudioManager *audio_manager = wakeup_manager->get_audio_manager(); CWakeupEngineManager *engine_manager = wakeup_manager->get_engine_manager(); @@ -658,17 +658,10 @@ bool CWakeupManager::start_streaming_utterance_data() mAudioManager.start_streaming_current_utterance_data(mLastWakeupEventInfo.wakeup_end_time); } - ecore_thread_main_loop_begin(); - if (mStreamingDurationTimer) { - ecore_timer_del(mStreamingDurationTimer); - mStreamingDurationTimer = nullptr; - } + stop_streaming_duration_timer(); if (streaming_by_manager) { - mStreamingDurationTimer = ecore_timer_add( - mWakeupSettings.get_streaming_duration_max(), - streaming_duration_expired, this); + start_streaming_duration_timer(); } - ecore_thread_main_loop_end(); MWR_LOGD("[END]"); return true; @@ -683,10 +676,7 @@ bool CWakeupManager::stop_streaming_utterance_data() mWakeupEngineManager.stop_streaming_current_utterance_data(); if (mStreamingDurationTimer) { - ecore_thread_main_loop_begin(); - ecore_timer_del(mStreamingDurationTimer); - mStreamingDurationTimer = nullptr; - ecore_thread_main_loop_end(); + stop_streaming_duration_timer(); } if (WAKEUP_MANAGER_STATE_UTTERANCE == mWakeupManagerState) { change_manager_state(WAKEUP_MANAGER_STATE_PROCESSING); @@ -717,15 +707,8 @@ bool CWakeupManager::start_streaming_follow_up_data() mAudioManager.start_streaming_follow_up_data(); - ecore_thread_main_loop_begin(); - if (mStreamingDurationTimer) { - ecore_timer_del(mStreamingDurationTimer); - mStreamingDurationTimer = nullptr; - } - mStreamingDurationTimer = ecore_timer_add( - mWakeupSettings.get_streaming_duration_max(), - streaming_duration_expired, this); - ecore_thread_main_loop_end(); + stop_streaming_duration_timer(); + start_streaming_duration_timer(); MWR_LOGD("[END]"); return true; @@ -740,10 +723,7 @@ bool CWakeupManager::stop_streaming_follow_up_data() mWakeupEngineManager.stop_streaming_current_utterance_data(); if (mStreamingDurationTimer) { - ecore_thread_main_loop_begin(); - ecore_timer_del(mStreamingDurationTimer); - mStreamingDurationTimer = nullptr; - ecore_thread_main_loop_end(); + stop_streaming_duration_timer(); } if (WAKEUP_MANAGER_STATE_UTTERANCE == mWakeupManagerState) { @@ -771,15 +751,8 @@ bool CWakeupManager::start_streaming_previous_utterance_data() mStreamingMode = STREAMING_MODE::PREVIOUS_UTTERANCE; mAudioManager.start_streaming_previous_utterance_data(); - ecore_thread_main_loop_begin(); - if (mStreamingDurationTimer) { - ecore_timer_del(mStreamingDurationTimer); - mStreamingDurationTimer = nullptr; - } - mStreamingDurationTimer = ecore_timer_add( - mWakeupSettings.get_streaming_duration_max(), - streaming_duration_expired, this); - ecore_thread_main_loop_end(); + stop_streaming_duration_timer(); + start_streaming_duration_timer(); MWR_LOGD("[END]"); return true; @@ -794,10 +767,7 @@ bool CWakeupManager::stop_streaming_previous_utterance_data() mWakeupEngineManager.stop_streaming_current_utterance_data(); if (mStreamingDurationTimer) { - ecore_thread_main_loop_begin(); - ecore_timer_del(mStreamingDurationTimer); - mStreamingDurationTimer = nullptr; - ecore_thread_main_loop_end(); + stop_streaming_duration_timer(); } if (WAKEUP_MANAGER_STATE_UTTERANCE == mWakeupManagerState) { @@ -906,6 +876,49 @@ void CWakeupManager::set_dependency_module_command(string engine_name, string co mWakeupEngineManager.engine_set_dependency_module_command(engine_name, command); } +void CWakeupManager::start_streaming_duration_timer() +{ + ecore_main_loop_thread_safe_call_async([](void* data) { + CWakeupManager* manager = static_cast(data); + if (!manager) return; + + CWakeupSettings *settings = manager->get_wakeup_settings(); + if (settings) { + Ecore_Timer* timer = ecore_timer_add( + settings->get_streaming_duration_max(), + streaming_duration_expired, manager); + manager->set_streaming_duration_timer(timer); + MWR_LOGI("DURATION_TIMER STARTED : %p", timer); + } + }, this); +} + +void CWakeupManager::stop_streaming_duration_timer() +{ + MWR_LOGI("DURATION_TIMER STOP"); + if (mStreamingDurationTimer) { + ecore_main_loop_thread_safe_call_async([](void* data) { + CWakeupManager* manager = static_cast(data); + if (!manager) return; + + Ecore_Timer* timer = manager->get_streaming_duration_timer(); + void* ret = ecore_timer_del(timer); + MWR_LOGI("DURATION_TIMER EXISTS : %p %p", timer, ret); + manager->set_streaming_duration_timer(nullptr); + }, this); + } +} + +void CWakeupManager::set_streaming_duration_timer(Ecore_Timer* timer) +{ + mStreamingDurationTimer = timer; +} + +Ecore_Timer* CWakeupManager::get_streaming_duration_timer() +{ + return mStreamingDurationTimer; +} + bool CWakeupManager::CEngineEventObserver::on_wakeup_event(string engine_name, mas_wakeup_event_info wakeup_info) { MWR_LOGD("[ENTER]"); @@ -977,6 +990,7 @@ bool CWakeupManager::CEngineEventObserver::on_streaming_audio_data( } if (MAS_SPEECH_STREAMING_EVENT_FINISH == event) { mWakeupManager->set_streaming_mode(STREAMING_MODE::NONE); + mWakeupManager->stop_streaming_duration_timer(); } return true; @@ -1066,6 +1080,7 @@ bool CWakeupManager::CAudioEventObserver::on_streaming_audio_data( } if (MAS_SPEECH_STREAMING_EVENT_FINISH == event) { mWakeupManager->set_streaming_mode(STREAMING_MODE::NONE); + mWakeupManager->stop_streaming_duration_timer(); } return true; diff --git a/plugins/wakeup-manager/src/wakeup_policy_default.cpp b/plugins/wakeup-manager/src/wakeup_policy_default.cpp index 7a471fd..e07374c 100644 --- a/plugins/wakeup-manager/src/wakeup_policy_default.cpp +++ b/plugins/wakeup-manager/src/wakeup_policy_default.cpp @@ -59,8 +59,10 @@ void CWakeupPolicyDefault::wakeup_candidate(mas_wakeup_event_info wakeup_info) { mWakeupInfos.push_back(wakeup_info); if (nullptr == mTimer) { + LOGD("Begin Ecore Thread Main Loop"); ecore_thread_main_loop_begin(); mTimer = ecore_timer_add(mDelaySeconds, timer_func, this); + LOGD("End Ecore Thread Main Loop"); ecore_thread_main_loop_end(); } } -- 2.7.4 From c6d3c1c29ba478e9ebe686ccafb2cdf83553b38d Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 16 Jul 2020 20:12:54 +0900 Subject: [PATCH 13/16] Ignore outdated wakeup timer events Change-Id: I0493c55d587c8d244a2db3f204592e259512172f --- src/multi_assistant_service_plugin.c | 86 ++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 24 deletions(-) diff --git a/src/multi_assistant_service_plugin.c b/src/multi_assistant_service_plugin.c index 6dedaf4..f34d095 100644 --- a/src/multi_assistant_service_plugin.c +++ b/src/multi_assistant_service_plugin.c @@ -93,48 +93,78 @@ Eina_Bool __send_result(void *data) } #endif /* -TEST_CODE */ -Eina_Bool process_wakeup_event_by_appid_timer(char* appid) +static int g_last_wakeup_event_id = 0; +typedef struct { + int id; + char* data; +} wakeup_event; + +void process_wakeup_event_by_appid_timer(wakeup_event* event) { - MAS_LOGD("[ENTER] appid(%s)", appid); + if (!event) return; + MAS_LOGD("[ENTER] appid(%s), id(%d), g_last_wakeup_event_id(%d)", + event->data, event->id, g_last_wakeup_event_id); + + if (!event->data) { + free(event); + return; + } + + if (event->id < g_last_wakeup_event_id) { + free(event->data); + free(event); + return; + } int pid = -1; - if (!appid) return ECORE_CALLBACK_CANCEL; - bool use_custom_ui = mas_get_client_custom_ui_option_by_appid(appid); + bool use_custom_ui = mas_get_client_custom_ui_option_by_appid(event->data); bool ui_panel_enabled = is_ui_panel_enabled(); if (ui_panel_enabled) masc_ui_dbus_enable_common_ui(!use_custom_ui); - mas_set_current_client_by_appid(appid); - if (ui_panel_enabled) masc_ui_dbus_change_assistant(appid); - if ((pid = mas_get_client_pid_by_appid(appid)) != -1) { + mas_set_current_client_by_appid(event->data); + if (ui_panel_enabled) masc_ui_dbus_change_assistant(event->data); + if ((pid = mas_get_client_pid_by_appid(event->data)) != -1) { mas_client_send_preprocessing_information(pid); mas_client_activate(pid); mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED); } else { // Appropriate MA Client not available, trying to launch new one - MAS_LOGD("MA Client with appid %s does not exist, launching client", appid); - mas_launch_client_by_appid(appid, CLIENT_LAUNCH_MODE_ACTIVATION); + MAS_LOGD("MA Client with appid %s does not exist, launching client", event->data); + mas_launch_client_by_appid(event->data, CLIENT_LAUNCH_MODE_ACTIVATION); } - if (appid) free(appid); + free(event->data); + free(event); MAS_LOGD("END"); - return ECORE_CALLBACK_CANCEL; + return; } -Eina_Bool process_wakeup_event_by_word_timer(char* wakeup_word) +void process_wakeup_event_by_word_timer(wakeup_event* event) { - MAS_LOGD("[ENTER]"); + if (!event) return; + MAS_LOGD("[ENTER] wakeword(%s), id(%d)", event->data, event->id); + + if (!event->data) { + free(event); + return; + } - if (!wakeup_word) return EINA_FALSE; + const char* appid = mas_get_client_appid_by_wakeup_word(event->data); - const char* appid = mas_get_client_appid_by_wakeup_word(wakeup_word); - process_wakeup_event_by_appid_timer(strdup(appid)); + wakeup_event* appid_timer_event = malloc(sizeof(wakeup_event)); + if (appid_timer_event) { + appid_timer_event->id = event->id; + appid_timer_event->data = strdup(appid ? appid : ""); + process_wakeup_event_by_appid_timer(event); + } - if (wakeup_word) free(wakeup_word); + free(event->data); + free(event); MAS_LOGD("END"); - return ECORE_CALLBACK_CANCEL; + return; } static void __wakeup_event_cb(mas_wakeup_event_info wakeup_info, void* user_data) @@ -206,13 +236,21 @@ static void __wakeup_event_cb(mas_wakeup_event_info wakeup_info, void* user_data } #endif /* - TEST_CODE */ if (wakeup_info.wakeup_appid) { - ecore_thread_main_loop_begin(); - ecore_timer_add(0.0f, process_wakeup_event_by_appid_timer, (void*)strdup(wakeup_info.wakeup_appid)); - ecore_thread_main_loop_end(); + wakeup_event* appid_timer_event = malloc(sizeof(wakeup_event)); + if (appid_timer_event) { + appid_timer_event->id = ++g_last_wakeup_event_id; + appid_timer_event->data = + strdup(wakeup_info.wakeup_appid ? wakeup_info.wakeup_appid : ""); + ecore_main_loop_thread_safe_call_async(process_wakeup_event_by_appid_timer, (void*)appid_timer_event); + } } else if (wakeup_info.wakeup_word) { - ecore_thread_main_loop_begin(); - ecore_timer_add(0.0f, process_wakeup_event_by_word_timer, (void*)strdup(wakeup_info.wakeup_word)); - ecore_thread_main_loop_end(); + wakeup_event* word_timer_event = malloc(sizeof(wakeup_event)); + if (word_timer_event) { + word_timer_event->id = ++g_last_wakeup_event_id; + word_timer_event->data = + strdup(wakeup_info.wakeup_word ? wakeup_info.wakeup_word : ""); + ecore_main_loop_thread_safe_call_async(process_wakeup_event_by_word_timer, (void*)word_timer_event); + } } } -- 2.7.4 From ed6f6921882fee2577b25be38ef2a2230c39ecef Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 16 Jul 2020 20:09:12 +0900 Subject: [PATCH 14/16] Add logs for checking wakeup_engine_command delivery Change-Id: Ib114ff5f46c96850d344eb26c43135f371222b74 --- plugins/wakeup-manager/src/wakeup_engine_manager.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/wakeup-manager/src/wakeup_engine_manager.cpp b/plugins/wakeup-manager/src/wakeup_engine_manager.cpp index d9181dc..40f6833 100644 --- a/plugins/wakeup-manager/src/wakeup_engine_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_engine_manager.cpp @@ -728,7 +728,8 @@ bool CWakeupEngineManager::on_audio_data_require_status(string engine_name, bool bool CWakeupEngineManager::on_wakeup_engine_command(string engine_name, mas_wakeup_engine_command_target_e target, string assistant_name, string command) { - MWR_LOGD("[ENTER]"); + MWR_LOGI("[ENTER] : %s %d %s %s", + engine_name.c_str(), target, assistant_name.c_str(), command.c_str()); for (const auto& observer : mObservers) { if (observer) { @@ -745,6 +746,7 @@ bool CWakeupEngineManager::on_wakeup_engine_command(string engine_name, mas_wake for (const auto& assistant : iter->assistant_list) { if (0 == assistant_name.compare(assistant) || MAS_WAKEUP_ENGINE_COMMAND_TARGET_ALL_ASSISTANTS == target) { + MWR_LOGI("Calling on_wakeup_engine_command for %s", assistant.c_str()); if (!observer->on_wakeup_engine_command(target, engine_name, assistant, command)) { LOGE("[Recorder WARNING] One of the observer returned false"); } -- 2.7.4 From eb0c49d73f42ef9d2adbad128bf0744b8807ba17 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Fri, 17 Jul 2020 21:29:55 +0900 Subject: [PATCH 15/16] Replace ecore_thread_main_loop_* functions with alternatives Change-Id: Ied3b35f41bb7c9f8bc74bc24d42e5a92e3b4b551 --- plugins/wakeup-manager/inc/wakeup_policy_default.h | 8 ++++++- .../wakeup-manager/src/wakeup_policy_default.cpp | 28 ++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/plugins/wakeup-manager/inc/wakeup_policy_default.h b/plugins/wakeup-manager/inc/wakeup_policy_default.h index d4b36b7..914c539 100644 --- a/plugins/wakeup-manager/inc/wakeup_policy_default.h +++ b/plugins/wakeup-manager/inc/wakeup_policy_default.h @@ -40,12 +40,18 @@ public: bool valid() override; void set_assistant_priority(string appid, int priority); - void set_delay(float seconds); void wakeup_candidate(mas_wakeup_event_info wakeup_info) override; void select_candidate(mas_wakeup_event_info wakeup_info) override; void timer_expired(); + + void set_delay(float seconds); + float get_delay(); + + void set_timer(Ecore_Timer* timer); + Ecore_Timer* get_timer(); + private: typedef struct { string appid; diff --git a/plugins/wakeup-manager/src/wakeup_policy_default.cpp b/plugins/wakeup-manager/src/wakeup_policy_default.cpp index e07374c..45b5caa 100644 --- a/plugins/wakeup-manager/src/wakeup_policy_default.cpp +++ b/plugins/wakeup-manager/src/wakeup_policy_default.cpp @@ -45,12 +45,28 @@ void CWakeupPolicyDefault::set_delay(float seconds) mDelaySeconds = seconds; } +float CWakeupPolicyDefault::get_delay() +{ + return mDelaySeconds; +} + +void CWakeupPolicyDefault::set_timer(Ecore_Timer* timer) +{ + mTimer = timer; +} + +Ecore_Timer* CWakeupPolicyDefault::get_timer() +{ + return mTimer; +} + static Eina_Bool timer_func(void *data) { LOGD("[ENTER]"); if (data) { CWakeupPolicyDefault *policy = static_cast(data); policy->timer_expired(); + policy->set_timer(nullptr); } return ECORE_CALLBACK_CANCEL; } @@ -59,11 +75,13 @@ void CWakeupPolicyDefault::wakeup_candidate(mas_wakeup_event_info wakeup_info) { mWakeupInfos.push_back(wakeup_info); if (nullptr == mTimer) { - LOGD("Begin Ecore Thread Main Loop"); - ecore_thread_main_loop_begin(); - mTimer = ecore_timer_add(mDelaySeconds, timer_func, this); - LOGD("End Ecore Thread Main Loop"); - ecore_thread_main_loop_end(); + ecore_main_loop_thread_safe_call_async([](void* data) { + CWakeupPolicyDefault* policy = static_cast(data); + if (!policy) return; + + Ecore_Timer* timer = ecore_timer_add(policy->get_delay(), timer_func, data); + policy->set_timer(timer); + }, this); } } -- 2.7.4 From 894ba9867035e67eda19e35f17e105f36cef911b Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Wed, 22 Jul 2020 17:21:24 +0900 Subject: [PATCH 16/16] Bump version to 0.2.36 Change-Id: Idf77f083e501e14f1c5b00f802cc01c60a929754 --- org.tizen.multi-assistant-service.xml | 2 +- packaging/org.tizen.multi-assistant-service.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.tizen.multi-assistant-service.xml b/org.tizen.multi-assistant-service.xml index c012fe7..13cc8d2 100644 --- a/org.tizen.multi-assistant-service.xml +++ b/org.tizen.multi-assistant-service.xml @@ -1,5 +1,5 @@ - + Won Nam Jang Sooyeon Kim diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index 5288e81..495fec1 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -1,6 +1,6 @@ Name: org.tizen.multi-assistant-service Summary: Multi assistant service -Version: 0.2.35 +Version: 0.2.36 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Flora-1.1 -- 2.7.4