Read default assistant setting when launching via voice key press 25/201625/6
authorJi-hoon Lee <dalton.lee@samsung.com>
Mon, 18 Mar 2019 08:26:52 +0000 (17:26 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Tue, 26 Mar 2019 07:09:22 +0000 (16:09 +0900)
Change-Id: Id3eb1947f465e3460e5ffdcab1a51599cb9d2fb6

plugins/wakeup-manager/src/wakeup_manager.cpp
src/multi_assistant_service.c
src/multi_assistant_service_plugin.c

index a5d8eb1cbba9e6a0a43855c31db97051ae4d4aeb..2d607fd8f981c6a356265550f4468870307e6ada 100644 (file)
@@ -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) {
index e92bf48a2779fc9e1421620c18a011ea29e8fe2f..c35f75aaa8f42a9ee1dc1f04ae55fd7016258f2d 100644 (file)
@@ -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;
index 93c2bb3a8501fb9b207ac4b30b15d8cd26ac004a..48dde712ea804d77c4a42d36f14b9ad9141e5c67 100644 (file)
@@ -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();
        }