From 88e3a75a466fc95af98d3f7abad4e3e2e812b0a4 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 18 Mar 2019 17:26:52 +0900 Subject: [PATCH] Read default assistant setting when launching via voice key press Change-Id: Id3eb1947f465e3460e5ffdcab1a51599cb9d2fb6 --- plugins/wakeup-manager/src/wakeup_manager.cpp | 20 +++++---- src/multi_assistant_service.c | 13 +++++- src/multi_assistant_service_plugin.c | 60 +++++++++++++-------------- 3 files changed, 52 insertions(+), 41 deletions(-) diff --git a/plugins/wakeup-manager/src/wakeup_manager.cpp b/plugins/wakeup-manager/src/wakeup_manager.cpp index a5d8eb1..2d607fd 100644 --- a/plugins/wakeup-manager/src/wakeup_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_manager.cpp @@ -463,7 +463,9 @@ static int wakeup_engine_info_initialize() void CWakeupEventObserver::on_wakeup(wakeup_event_info info) { - g_wakeup_event_cb(info, g_wakeup_event_user_data); + if (NULL != g_wakeup_event_cb) { + g_wakeup_event_cb(info, g_wakeup_event_user_data); + } } void wakeup_policy_initialize(void) @@ -849,14 +851,14 @@ int wakeup_manager_process_event(int event, void* data, int len) g_voice_key_pressed = true; /* (Re)Start recorder thread using bt hid */ g_audio_manager.start_recording(); - for (int loop = 0;loop < g_engine_count;loop++) { - /* Need to find the default assistant, for now assuming 0 is the one */ - if(loop == 0) { - wakeup_event_info event; - event.wakeup_word = "hi bixby"; - event.wakeup_appid = g_wakeup_engine_info[loop].assistant_list.at(0).c_str(); - g_wakeup_event_cb(event, g_wakeup_event_user_data); - } + + /* Wakeup default assistant */ + /* TODO: apply conversation timeout for selecting assistant here */ + wakeup_event_info event; + event.wakeup_word = nullptr; + event.wakeup_appid = g_wakeup_settings.default_assistant_appid.c_str(); + if (NULL != g_wakeup_event_cb) { + g_wakeup_event_cb(event, g_wakeup_event_user_data); } } } else if (event == MA_PLUGIN_EVENT_VOICE_KEY_RELEASED) { diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c index e92bf48..c35f75a 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.c @@ -744,8 +744,17 @@ int mas_launch_client_by_appid(const char *appid) app_control_destroy (app_control); if (APP_CONTROL_ERROR_NONE == ret) { - g_wakeup_maclient_appid = appid; - MAS_LOGD("g_wakeup_maclient_appid : %s", appid); + bool found = false; + for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) { + if (g_maclient_info[loop].used && + 0 < strlen(g_maclient_info[loop].appid)) { + if (strncmp(appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) { + g_wakeup_maclient_appid = g_maclient_info[loop].appid; + found = true; + } + } + } + MAS_LOGD("g_wakeup_maclient_appid : %s, %d", g_wakeup_maclient_appid, found); } return ret; diff --git a/src/multi_assistant_service_plugin.c b/src/multi_assistant_service_plugin.c index 93c2bb3..48dde71 100644 --- a/src/multi_assistant_service_plugin.c +++ b/src/multi_assistant_service_plugin.c @@ -82,48 +82,44 @@ Eina_Bool __send_result(void *data) } #endif /* -TEST_CODE */ -Eina_Bool __launch_assistant_by_wakeup_word(void *data) +Eina_Bool __launch_assistant_by_wakeup_appid_timer(char* appid) { MAS_LOGD("[ENTER]"); int pid = -1; - char *wakeup_word = (char*)data; - if (!wakeup_word) return EINA_FALSE; + if (!appid) return ECORE_CALLBACK_CANCEL; - mas_set_current_client_by_wakeup_word(wakeup_word); - masc_ui_dbus_change_assistant(mas_get_client_appid_by_wakeup_word(wakeup_word)); - if ((pid = mas_get_client_pid_by_wakeup_word(wakeup_word)) != -1) { + mas_set_current_client_by_appid(appid); + masc_ui_dbus_change_assistant(appid); + if ((pid = mas_get_client_pid_by_appid(appid)) != -1) { masc_dbus_active_state_change(pid, MA_ACTIVE_STATE_ACTIVE); /* Bring MA client to foreground - is there a better way instead of launching? */ - mas_launch_client_by_wakeup_word(wakeup_word); - /* - MAS_LOGD("MA Client with wakeup word %s exists, requesting speech data", (wakeup_word ? wakeup_word : "NULL")); - int ret = -1; - if (NULL != g_handle) { - wakeup_manager_start_streaming_utterance_data func = - _wakeup_manager_interface.start_streaming_utterance_data; - if (NULL == func) { - MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_UTTERANCE_DATA); - } else { - ret = func(); - if (0 != ret) { - MAS_LOGE("[ERROR] Fail to request speech data(%d)", ret); - } - } - } else { - MAS_LOGE("[ERROR] g_handle is not valid"); - } - */ + mas_launch_client_by_appid(appid); } else { // Appropriate MA Client not available, trying to launch new one - MAS_LOGD("MA Client with wakeup word %s does not exist, launching client", (wakeup_word ? wakeup_word : "NULL")); - mas_launch_client_by_wakeup_word(wakeup_word); + MAS_LOGD("MA Client with appid %s does not exist, launching client", appid); + mas_launch_client_by_appid(appid); } + if (appid) free(appid); + + MAS_LOGD("END"); + return ECORE_CALLBACK_CANCEL; +} + +Eina_Bool __launch_assistant_by_wakeup_word_timer(char* wakeup_word) +{ + MAS_LOGD("[ENTER]"); + + if (!wakeup_word) return EINA_FALSE; + + const char* appid = mas_get_client_appid_by_wakeup_word(wakeup_word); + __launch_assistant_by_wakeup_appid_timer(strdup(appid)); + if (wakeup_word) free(wakeup_word); MAS_LOGD("END"); - return EINA_FALSE; + return ECORE_CALLBACK_CANCEL; } static void __wakeup_event_cb(wakeup_event_info event, void* user_data) @@ -191,9 +187,13 @@ static void __wakeup_event_cb(wakeup_event_info event, void* user_data) ecore_thread_main_loop_end(); } #endif /* - TEST_CODE */ - if (event.wakeup_word) { + if (event.wakeup_appid) { + ecore_thread_main_loop_begin(); + ecore_timer_add(0.0f, __launch_assistant_by_wakeup_appid_timer, (void*)strdup(event.wakeup_appid)); + ecore_thread_main_loop_end(); + } else if (event.wakeup_word) { ecore_thread_main_loop_begin(); - ecore_timer_add(0.0f, __launch_assistant_by_wakeup_word, (void*)strdup(event.wakeup_word)); + ecore_timer_add(0.0f, __launch_assistant_by_wakeup_word_timer, (void*)strdup(event.wakeup_word)); ecore_thread_main_loop_end(); } -- 2.7.4