From 1eda268930725ae49383d285facd4ad35c78ee40 Mon Sep 17 00:00:00 2001 From: "jingjin.geng" Date: Fri, 14 Jun 2019 03:42:49 +0800 Subject: [PATCH] (de)activate wakeup engines by voice_input_language Change-Id: I675d75db15e9b8b1f4540754dd2c51d77a7eba88 --- inc/multi_assistant_config.h | 6 +- inc/multi_assistant_service_plugin.h | 5 -- .../inc/wakeup_engine_manager.h | 8 ++- plugins/wakeup-manager/inc/wakeup_manager.h | 23 +++++-- .../inc/wakeup_manager_wrapper.h | 2 - plugins/wakeup-manager/inc/wakeup_settings.h | 19 +++++- .../src/wakeup_engine_manager.cpp | 50 ++++++++++++-- plugins/wakeup-manager/src/wakeup_manager.cpp | 54 +++++++++++---- .../src/wakeup_manager_wrapper.cpp | 16 ----- .../wakeup-manager/src/wakeup_settings.cpp | 67 +++++++++++++++---- src/multi_assistant_config.c | 15 ++++- src/multi_assistant_service.c | 47 +++++++++++-- src/multi_assistant_service_plugin.c | 22 ------ 13 files changed, 236 insertions(+), 98 deletions(-) diff --git a/inc/multi_assistant_config.h b/inc/multi_assistant_config.h index 454bc10..d117b81 100644 --- a/inc/multi_assistant_config.h +++ b/inc/multi_assistant_config.h @@ -55,6 +55,7 @@ typedef struct { const char* name; const char* icon_path; const char* wakeup_list[MAX_WAKEUP_LIST_NUM]; + const char* wakeup_language[MAX_WAKEUP_LIST_NUM]; int cnt_wakeup; const char* supported_lang[MAX_SUPPORTED_LANGUAGE_NUM]; int cnt_lang; @@ -62,7 +63,10 @@ typedef struct { bool custom_ui_option; } ma_assistant_info_s; -typedef int (*mas_config_assistant_info_cb)(const char* appid, const char* name, const char* icon_path, const char* wakeup_list[], int cnt_wakeup, const char* supported_lang[], int cnt_lang, const char* wakeup_engine, bool custom_ui_option, void* user_data); +typedef int (*mas_config_assistant_info_cb)(const char* appid, const char* name, const char* icon_path, + const char* wakeup_list[], const char* wakeup_language[], int cnt_wakeup, + const char* supported_lang[], int cnt_lang, + const char* wakeup_engine, bool custom_ui_option, void* user_data); int mas_config_get_assistant_info(mas_config_assistant_info_cb callback, void* user_data); #ifdef __cplusplus diff --git a/inc/multi_assistant_service_plugin.h b/inc/multi_assistant_service_plugin.h index c68eead..57bb958 100644 --- a/inc/multi_assistant_service_plugin.h +++ b/inc/multi_assistant_service_plugin.h @@ -53,8 +53,6 @@ int multi_assistant_service_plugin_add_assistant_language(const char* appid, con int multi_assistant_service_plugin_set_assistant_wakeup_engine(const char* appid, const char* engine); -int multi_assistant_service_plugin_set_assistant_enabled(const char* appid, int enabled); - int multi_assistant_service_plugin_activate(void); int multi_assistant_service_plugin_deactivate(void); @@ -116,8 +114,6 @@ typedef int (*wakeup_manager_add_assistant_wakeup_word)(const char* appid, const typedef int (*wakeup_manager_add_assistant_language)(const char* appid, const char* language); #define MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE "wakeup_manager_set_assistant_wakeup_engine" typedef int (*wakeup_manager_set_assistant_wakeup_engine)(const char* appid, const char* engine); -#define MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_ENABLED "wakeup_manager_set_assistant_enabled" -typedef int (*wakeup_manager_set_assistant_enabled)(const char* appid, int enabled); #define MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE "wakeup_manager_set_language" typedef int (*wakeup_manager_set_language)(const char* language); #define MA_WAKEUP_MANAGER_FUNC_ACTIVATE "wakeup_manager_activate" @@ -170,7 +166,6 @@ typedef struct { wakeup_manager_add_assistant_wakeup_word add_assistant_wakeup_word; wakeup_manager_add_assistant_language add_assistant_language; wakeup_manager_set_assistant_wakeup_engine set_assistant_wakeup_engine; - wakeup_manager_set_assistant_enabled set_assistant_enabled; wakeup_manager_set_language set_language; wakeup_manager_activate activate; wakeup_manager_deactivate deactivate; diff --git a/plugins/wakeup-manager/inc/wakeup_engine_manager.h b/plugins/wakeup-manager/inc/wakeup_engine_manager.h index e64faf7..23f5e57 100644 --- a/plugins/wakeup-manager/inc/wakeup_engine_manager.h +++ b/plugins/wakeup-manager/inc/wakeup_engine_manager.h @@ -23,6 +23,7 @@ #include #include #include +#include namespace multiassistant { @@ -128,6 +129,9 @@ public: bool get_audio_data_required(); void set_selected_wakeup_info(wakeup_event_info info); + bool set_language(string language); + void set_assistant_activated(string appid, bool activated); + void start_streaming_current_utterance_data(); void stop_streaming_current_utterance_data(); @@ -145,12 +149,12 @@ public: private: typedef struct { string engine_name; - bool active{false}; - bool enabled{false}; + bool activated{false}; bool audio_data_require_status{false}; string engine_path; wakeup_engine_interface interface{nullptr, }; vector assistant_list; + set activated_assistants; void *engine_handle{nullptr}; } EngineInfo; diff --git a/plugins/wakeup-manager/inc/wakeup_manager.h b/plugins/wakeup-manager/inc/wakeup_manager.h index a129f9d..d94b4ad 100644 --- a/plugins/wakeup-manager/inc/wakeup_manager.h +++ b/plugins/wakeup-manager/inc/wakeup_manager.h @@ -25,6 +25,7 @@ #include "wakeup_policy_default.h" #include +#include namespace multiassistant { @@ -73,7 +74,6 @@ public: bool add_assistant_language(string appid, string language); bool add_assistant_wakeup_word(string appid, string wakeup_word, string language); bool set_assistant_wakeup_engine(string appid, string engine); - bool set_assistant_enabled(string appid, bool enabled); bool update_voice_feedback_state(string appid, bool state); bool send_assistant_specific_command(string appid, string command); @@ -147,14 +147,26 @@ private: CWakeupManager *mWakeupManager{nullptr}; CWakeupEngineManager *mEngineManager{nullptr}; }; + + class CSettingsEventObserver : public ISettingsEventObserver + { + public: + bool on_voice_input_language_changed(const char* language) override; + + void set_wakeup_manager(CWakeupManager *manager) { mWakeupManager = manager; } + private: + CWakeupManager *mWakeupManager{nullptr}; + }; + + void initialize_wakeup_policy(); + typedef struct { string appid; vector languageList; - } LanguageInfo; - - void initialize_wakeup_policy(); + } AssistantLanguageInfo; + vector mAssistantLanguageInfo; + map mAssistantActivated; - vector mLanguageInfo; vector mObservers; unique_ptr mWakeupPolicy; @@ -166,6 +178,7 @@ private: CAudioEventObserver mAudioEventObserver; CEngineEventObserver mEngineEventObserver; CPolicyEventObserver mPolicyEventObserver; + CSettingsEventObserver mSettingsEventObserver; thread mEngineDataThread; atomic_bool mStopEngineDataThread{false}; diff --git a/plugins/wakeup-manager/inc/wakeup_manager_wrapper.h b/plugins/wakeup-manager/inc/wakeup_manager_wrapper.h index 93d71f5..9fc88a1 100644 --- a/plugins/wakeup-manager/inc/wakeup_manager_wrapper.h +++ b/plugins/wakeup-manager/inc/wakeup_manager_wrapper.h @@ -82,8 +82,6 @@ EXPORT_API int wakeup_manager_add_assistant_language(const char* appid, const ch EXPORT_API int wakeup_manager_set_assistant_wakeup_engine(const char* appid, const char *engine); -EXPORT_API int wakeup_manager_set_assistant_enabled(const char* appid, int enabled); - EXPORT_API int wakeup_manager_set_language(const char* language); EXPORT_API int wakeup_manager_activate(void); diff --git a/plugins/wakeup-manager/inc/wakeup_settings.h b/plugins/wakeup-manager/inc/wakeup_settings.h index 4e55aa0..e99c72e 100644 --- a/plugins/wakeup-manager/inc/wakeup_settings.h +++ b/plugins/wakeup-manager/inc/wakeup_settings.h @@ -19,6 +19,9 @@ #include #include +#include + +typedef void (*input_language_changed_cb)(void* data); namespace multiassistant { @@ -37,6 +40,14 @@ using namespace std; #define WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_DELAY "db/multi-assistant/wakeup_policy_delay" #define WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_PRIORITY "db/multi-assistant/wakeup_policy_priority" #define WAKEUP_SETTINGS_KEY_STREAMING_DURATION_MAX "db/multi-assistant/streaming_duration_max" +#define WAKEUP_SETTINGS_KEY_VOICE_INPUT_LANGUAGE "db/multi-assistant/voice_input_language" + +class ISettingsEventObserver +{ +public: + virtual ~ISettingsEventObserver() = default; + virtual bool on_voice_input_language_changed(const char* language) = 0; +}; class CWakeupSettings { @@ -50,6 +61,10 @@ public: void initialize(); void deinitialize(); + void subscribe(ISettingsEventObserver *observer); + void unsubscribe(ISettingsEventObserver *observer); + vector get_observers(); + string get_default_assistant_appid(); bool get_ui_panel_enabled(); float get_conversation_timeout(); @@ -58,8 +73,10 @@ public: float get_wakeup_policy_delay(); vector get_wakeup_policy_priority(); float get_streaming_duration_max(); - void set_assistant_enabled(string appid, bool enabled); + string get_current_language(void); private: + vector mObservers; + string mDefaultAssistantAppid{DEFAULT_ASSISTANT_APPID}; bool mUiPanelEnabled{true}; float mConversationTimeout{5.0}; diff --git a/plugins/wakeup-manager/src/wakeup_engine_manager.cpp b/plugins/wakeup-manager/src/wakeup_engine_manager.cpp index e5f76ed..891dea1 100644 --- a/plugins/wakeup-manager/src/wakeup_engine_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_engine_manager.cpp @@ -18,7 +18,7 @@ static int g_speech_pcm_wait_count = 400; template static auto contains(const C& v, const T& x) -> decltype(end(v), true) { - return end(v) != find(begin(v), end(v), x); + return end(v) != find(begin(v), end(v), x); } CWakeupEngineManager::CWakeupEngineManager() @@ -133,6 +133,46 @@ void CWakeupEngineManager::set_selected_wakeup_info(wakeup_event_info wakeup_inf } } +bool CWakeupEngineManager::set_language(string language) +{ + for (const auto& info : mEngineInfo) { + if (info.interface.set_language) { + info.interface.set_language(language.c_str()); + } + } +} + +void CWakeupEngineManager::set_assistant_activated(string appid, bool activated) +{ + MWR_LOGD("[ENTER] : %s %d", appid.c_str(), activated); + for (auto& info : mEngineInfo) { + const auto& iter = find_if(info.assistant_list.begin(), info.assistant_list.end(), + [appid](const string& assistant) { + return (0 == assistant.compare(appid)); + }); + + /* If the appid is in the assistant list */ + if (info.assistant_list.end() != iter) { + bool previously_activated = info.activated; + if (activated) { + info.activated_assistants.insert(appid); + } else { + info.activated_assistants.erase(appid); + } + info.activated = (info.activated_assistants.size() > 0); + if (previously_activated != info.activated) { + if (info.activated) { + info.interface.activate(); + } else { + info.interface.deactivate(); + } + /* Activated status changed, need to update audio_data_require_status too */ + on_audio_data_require_status(info.engine_name, info.audio_data_require_status); + } + } + } +} + void CWakeupEngineManager::streaming_speech_data_thread_func() { MWR_LOGD("[ENTER]"); @@ -357,7 +397,7 @@ bool CWakeupEngineManager::on_error(string engine_name, int error_code, string e bool CWakeupEngineManager::on_audio_data_require_status(string engine_name, bool require) { - MWR_LOGD("[ENTER]"); + MWR_LOGD("[ENTER] %s, %d", engine_name.c_str(), require); bool found = false; // LOCK REQUIRED @@ -367,7 +407,7 @@ bool CWakeupEngineManager::on_audio_data_require_status(string engine_name, bool found = true; info.audio_data_require_status = require; } - if (info.enabled && info.audio_data_require_status) { + if (info.activated && info.audio_data_require_status) { count++; } } @@ -462,9 +502,7 @@ void CWakeupEngineManager::add_engine(string name, string path) info.engine_path = path; info.engine_name = name; - info.active = false; - /* We'll need to check vconf for enabled wakeup engines */ - info.enabled = true; + info.activated = false; info.audio_data_require_status = false; /* All the necessary information has already been set properly */ diff --git a/plugins/wakeup-manager/src/wakeup_manager.cpp b/plugins/wakeup-manager/src/wakeup_manager.cpp index 83c7320..0eaeb2c 100644 --- a/plugins/wakeup-manager/src/wakeup_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_manager.cpp @@ -20,7 +20,6 @@ #include "dependency_resolver.h" #include - namespace multiassistant { namespace wakeup @@ -94,6 +93,7 @@ bool CWakeupManager::initialize() mPolicyEventObserver.set_wakeup_manager(this); mEngineEventObserver.set_wakeup_manager(this); mAudioEventObserver.set_wakeup_manager(this); + mSettingsEventObserver.set_wakeup_manager(this); mWakeupSettings.initialize(); @@ -112,6 +112,8 @@ bool CWakeupManager::initialize() dependency_resolver_initialize(interface); + mWakeupSettings.subscribe(&mSettingsEventObserver); + MWR_LOGD("[END]"); return true; } @@ -129,7 +131,8 @@ bool CWakeupManager::deinitialize() mAudioManager.deinitialize(); mWakeupSettings.deinitialize(); - mLanguageInfo.clear(); + mAssistantLanguageInfo.clear(); + MWR_LOGD("[END]"); return true; } @@ -154,6 +157,9 @@ bool CWakeupManager::activate(void) if (WAKEUP_MANAGER_STATE_INACTIVE != mWakeupManagerState) return false; + /* Activate assistants that supports current voice input language */ + set_language(mWakeupSettings.get_current_language()); + change_manager_state(WAKEUP_MANAGER_STATE_LISTENING); if (mWakeupEngineManager.get_audio_data_required()) { mAudioManager.start_recording(); @@ -181,17 +187,17 @@ bool CWakeupManager::add_assistant_language(string appid, string language) { MWR_LOGD("[ENTER]"); bool found = false; - for (auto& info : mLanguageInfo) { + for (auto& info : mAssistantLanguageInfo) { if(0 == info.appid.compare(appid)) { info.languageList.push_back(language); found = true; } } if(false == found) { - LanguageInfo info; + AssistantLanguageInfo info; info.appid = appid; info.languageList.push_back(language); - mLanguageInfo.push_back(info); + mAssistantLanguageInfo.push_back(info); } MWR_LOGD("[END]"); return true; @@ -217,21 +223,33 @@ bool CWakeupManager::set_assistant_wakeup_engine(string appid, string engine) return true; } -bool CWakeupManager::set_assistant_enabled(string appid, bool enabled) -{ - MWR_LOGD("[ENTER]"); - mWakeupSettings.set_assistant_enabled(appid, enabled); - MWR_LOGD("[END]"); - return true; -} - bool CWakeupManager::set_language(string language) { bool ret = false; - MWR_LOGD("[ENTER]"); + MWR_LOGD("[ENTER] : %s", language.c_str()); if (check_language_valid(language)) { mCurrentLanguage = language; + + bool found = false; + for (auto& info : mAssistantLanguageInfo) { + found = false; + for(auto it = info.languageList.begin(); it != info.languageList.end(); it++) { + if(language == *it) { + found = true; + break; + } + } + if(false == found) { + mAssistantActivated[info.appid] = false; + } else { + mAssistantActivated[info.appid] = true; + } + + mWakeupEngineManager.set_assistant_activated(info.appid, found); + } + + mWakeupEngineManager.set_language(language); ret = true; } else { MWR_LOGE("[ERROR] Not supported language (%s)", language.c_str()); @@ -727,5 +745,13 @@ bool CWakeupManager::CAudioEventObserver::on_streaming_audio_data( return true; } +bool CWakeupManager::CSettingsEventObserver::on_voice_input_language_changed( + const char* language) +{ + if (nullptr == mWakeupManager || nullptr == language) return false; + mWakeupManager->set_language(std::string(language)); + return true; +} + } // wakeup } // multiassistant diff --git a/plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp b/plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp index 6424077..1dc8a06 100644 --- a/plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp +++ b/plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp @@ -149,22 +149,6 @@ int wakeup_manager_set_assistant_wakeup_engine(const char* appid, const char* en return 0; } -int wakeup_manager_set_assistant_enabled(const char* appid, int enabled) -{ - MWR_LOGD("[ENTER]"); - - if (NULL == appid) { - MWR_LOGD("[ERROR] Parameter is invalid, appid(%s)", appid); - return -1; - } - - g_wakeup_manager.set_assistant_enabled(string{appid}, enabled); - - MWR_LOGD("[END]"); - - return 0; -} - int wakeup_manager_set_language(const char* language) { MWR_LOGD("[ENTER]"); diff --git a/plugins/wakeup-manager/src/wakeup_settings.cpp b/plugins/wakeup-manager/src/wakeup_settings.cpp index 4ed21b3..f53cf77 100644 --- a/plugins/wakeup-manager/src/wakeup_settings.cpp +++ b/plugins/wakeup-manager/src/wakeup_settings.cpp @@ -1,8 +1,8 @@ #include "wakeup_settings.h" #include "wakeup_manager_main.h" -#include #include +#include namespace multiassistant { @@ -17,6 +17,28 @@ CWakeupSettings::~CWakeupSettings() { } +static void wakeup_setting_input_language_changed_cb(keynode_t *node, void* data) +{ + if (nullptr == node) return; + + CWakeupSettings* settings = static_cast(data); + if (nullptr == settings) return; + + if (VCONF_TYPE_STRING == node->type) { + const char* value = static_cast(node->value.s); + vector observers = settings->get_observers(); + for (const auto& observer : observers) { + if (observer) { + if (!observer->on_voice_input_language_changed(value)) { + LOGW("[Settings WARNING] One of the observer returned false"); + } + } + } + } else { + LOGE("[Settings ERROR] the value type is not string : %d", node->type); + } +} + void CWakeupSettings::initialize() { int vconf_ret; @@ -80,10 +102,32 @@ void CWakeupSettings::initialize() mStreamingDurationMax = vconf_double; MWR_LOGD("streaming_duration_max : %f", mStreamingDurationMax); } + + vconf_notify_key_changed(WAKEUP_SETTINGS_KEY_VOICE_INPUT_LANGUAGE, + wakeup_setting_input_language_changed_cb, this); } void CWakeupSettings::deinitialize() { + vconf_ignore_key_changed(WAKEUP_SETTINGS_KEY_VOICE_INPUT_LANGUAGE, NULL); +} + +void CWakeupSettings::subscribe(ISettingsEventObserver *observer) +{ + mObservers.push_back(observer); +} + +void CWakeupSettings::unsubscribe(ISettingsEventObserver *observer) +{ + auto iter = find(mObservers.begin(), mObservers.end(), observer); + if (iter != mObservers.end()) { + mObservers.erase(iter); + } +} + +vector CWakeupSettings::get_observers() +{ + return mObservers; } string CWakeupSettings::get_default_assistant_appid() @@ -135,21 +179,16 @@ float CWakeupSettings::get_streaming_duration_max() return mStreamingDurationMax; } -void CWakeupSettings::set_assistant_enabled(string appid, bool enabled) +std::string CWakeupSettings::get_current_language(void) { - int found = 0; - for(auto it = mEnabledAssistants.begin(); it != mEnabledAssistants.end(); it++) { - if(appid == *it) { - if(false == enabled) { - mEnabledAssistants.erase(it); - } - found = 1; - break; - } - } - if((0 == found) && (true == enabled)) { - mEnabledAssistants.push_back(appid); + std::string result{"en_US"}; + char* language = vconf_get_str(WAKEUP_SETTINGS_KEY_VOICE_INPUT_LANGUAGE); + if (language) { + result = language; + free(language); } + return result; } + } // wakeup } // multiassistant diff --git a/src/multi_assistant_config.c b/src/multi_assistant_config.c index c15f73f..25b3fdf 100644 --- a/src/multi_assistant_config.c +++ b/src/multi_assistant_config.c @@ -77,6 +77,7 @@ int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, const temp->name = NULL; temp->icon_path = NULL; memset(temp->wakeup_list, 0x00, sizeof(temp->wakeup_list)); + memset(temp->wakeup_language, 0x00, sizeof(temp->wakeup_language)); temp->cnt_wakeup = 0; memset(temp->supported_lang, 0x00, sizeof(temp->supported_lang)); temp->cnt_lang = 0; @@ -104,10 +105,17 @@ int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, const if (child_node->name && 0 == xmlStrcmp(child_node->name, (const xmlChar*)MA_TAG_ASSISTANT_WAKEUP_WORD)) { key = xmlNodeGetContent(child_node); if (key) { - temp->wakeup_list[temp->cnt_wakeup++] = strdup((const char*)key); + temp->wakeup_list[temp->cnt_wakeup] = strdup((const char*)key); MAS_LOGD("Wakeup Word : %s", key); xmlFree(key); } + xmlChar* prop = xmlNodeGetLang(child_node); + if (prop) { + temp->wakeup_language[temp->cnt_wakeup] = strdup((const char*)prop); + MAS_LOGD("Wakeup Language for %s : %s", temp->wakeup_list[temp->cnt_wakeup], prop); + xmlFree(prop); + } + temp->cnt_wakeup++; } child_node = child_node->next; @@ -156,8 +164,9 @@ int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, const if (callback) { callback(temp->app_id, temp->name, temp->icon_path, - temp->wakeup_list, temp->cnt_wakeup, temp->supported_lang, - temp->cnt_lang, temp->wakeup_engine, temp->custom_ui_option, user_data); + temp->wakeup_list, temp->wakeup_language, temp->cnt_wakeup, + temp->supported_lang, temp->cnt_lang, + temp->wakeup_engine, temp->custom_ui_option, user_data); } if (temp->app_id) { diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c index e73a723..a1b1f54 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.c @@ -40,13 +40,17 @@ static const char *g_current_lang = "en_US"; #define MULTI_ASSISTANT_SETTINGS_ACTIVATED "db/multi-assistant/activated" #define MAX_MACLIENT_INFO_NUM 16 -#define MAX_WAKEUP_WORDS_NUM 4 -#define MAX_WAKEUP_WORD_LEN 255 +#define MAX_WAKEUP_WORDS_NUM 255 +#define MAX_WAKEUP_WORD_LEN 32 +#define MAX_SUPPORTED_LANGUAGES_NUM 255 +#define MAX_SUPPORTED_LANGUAGE_LEN 16 typedef struct { bool used; char appid[MAX_APPID_LEN]; char wakeup_word[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN]; + char wakeup_language[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]; char wakeup_engine[MAX_APPID_LEN]; + char supported_language[MAX_SUPPORTED_LANGUAGES_NUM][MAX_SUPPORTED_LANGUAGE_LEN]; bool custom_ui_option; } ma_client_info; @@ -434,8 +438,8 @@ int mas_ui_client_change_assistant(const char* appid) return 0; } -int __mas_assistant_info_cb(const char* appid, const char* name, - const char* icon_path, const char* wakeup_list[], int cnt_wakeup, +int __mas_assistant_info_cb(const char* appid, const char* name, const char* icon_path, + const char* wakeup_list[], const char* wakeup_language[], int cnt_wakeup, const char* supported_lang[], int cnt_lang, const char* wakeup_engine, bool custom_ui_option, void* user_data) { MAS_LOGD("__mas_assistant_info_cb called"); @@ -461,14 +465,30 @@ int __mas_assistant_info_cb(const char* appid, const char* name, for (loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) { if (loop < cnt_wakeup && wakeup_list[loop]) { - MAS_LOGD("wakeup_list(%d)(%s)", loop, wakeup_list[loop]); + MAS_LOGD("wakeup_list(%d)(%s)(%s)", loop, wakeup_list[loop], wakeup_language[loop]); strncpy(g_maclient_info[index].wakeup_word[loop], wakeup_list[loop], MAX_WAKEUP_WORD_LEN); g_maclient_info[index].wakeup_word[loop][MAX_WAKEUP_WORD_LEN - 1] = '\0'; + if (wakeup_language[loop]) { + strncpy(g_maclient_info[index].wakeup_language[loop], wakeup_language[loop], MAX_SUPPORTED_LANGUAGE_LEN); + g_maclient_info[index].wakeup_language[loop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0'; + } else { + strncpy(g_maclient_info[index].wakeup_language[loop], "", MAX_SUPPORTED_LANGUAGE_LEN); + } } else { strncpy(g_maclient_info[index].wakeup_word[loop], "", MAX_WAKEUP_WORD_LEN); } } + for (loop = 0;loop < MAX_SUPPORTED_LANGUAGES_NUM;loop++) { + if (loop < cnt_lang && supported_lang[loop]) { + MAS_LOGD("supported_lang(%d)(%s)", loop, supported_lang[loop]); + strncpy(g_maclient_info[index].supported_language[loop], supported_lang[loop], MAX_SUPPORTED_LANGUAGE_LEN); + g_maclient_info[index].supported_language[loop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0'; + } else { + strncpy(g_maclient_info[index].supported_language[loop], "", MAX_SUPPORTED_LANGUAGE_LEN); + } + } + MAS_LOGD("wakeup_engine(%s)", wakeup_engine); if (wakeup_engine) { strncpy(g_maclient_info[index].wakeup_engine, wakeup_engine, MAX_APPID_LEN); @@ -522,6 +542,7 @@ static int init_wakeup(void) if (0 == mas_config_get_assistant_info(__mas_assistant_info_cb, NULL)) { for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) { + int inner_loop; if (g_maclient_info[loop].used && 0 < strlen(g_maclient_info[loop].appid)) { if (0 < strlen(g_maclient_info[loop].wakeup_engine)) { @@ -529,17 +550,29 @@ static int init_wakeup(void) g_maclient_info[loop].appid, g_maclient_info[loop].wakeup_engine); } - for (int inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) { + for (inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) { if (0 < strlen(g_maclient_info[loop].wakeup_word[inner_loop])) { MAS_LOGD("Registering wakeup word %s for app %s", g_maclient_info[loop].wakeup_word[inner_loop], g_maclient_info[loop].appid); if (0 != multi_assistant_service_plugin_add_assistant_wakeup_word( g_maclient_info[loop].appid, - g_maclient_info[loop].wakeup_word[inner_loop], "en_US")) { + g_maclient_info[loop].wakeup_word[inner_loop], + g_maclient_info[loop].wakeup_language[inner_loop])) { MAS_LOGE("Fail to add assistant's wakeup word"); } } } + for (inner_loop = 0; inner_loop < MAX_SUPPORTED_LANGUAGE_NUM; inner_loop++) { + if (0 < strlen(g_maclient_info[loop].supported_language[inner_loop])) { + MAS_LOGD("Adding language %s for app %s", + g_maclient_info[loop].supported_language[inner_loop], g_maclient_info[loop].appid); + if (0 != multi_assistant_service_plugin_add_assistant_language( + g_maclient_info[loop].appid, + g_maclient_info[loop].supported_language[inner_loop])) { + MAS_LOGE("Fail to add assistant's language"); + } + } + } } } } else { diff --git a/src/multi_assistant_service_plugin.c b/src/multi_assistant_service_plugin.c index 4b40351..1669d34 100644 --- a/src/multi_assistant_service_plugin.c +++ b/src/multi_assistant_service_plugin.c @@ -360,9 +360,6 @@ int multi_assistant_service_plugin_initialize(void) _wakeup_manager_interface.set_assistant_wakeup_engine = (wakeup_manager_set_assistant_wakeup_engine)dlsym(g_handle, MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE); - _wakeup_manager_interface.set_assistant_enabled = - (wakeup_manager_set_assistant_enabled)dlsym(g_handle, - MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_ENABLED); _wakeup_manager_interface.set_language = (wakeup_manager_set_language)dlsym(g_handle, MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE); @@ -587,25 +584,6 @@ int multi_assistant_service_plugin_set_assistant_wakeup_engine(const char* appid return ret; } -int multi_assistant_service_plugin_set_assistant_enabled(const char* appid, int enabled) -{ - int ret = -1; - if (NULL != g_handle) { - wakeup_manager_set_assistant_enabled func = _wakeup_manager_interface.set_assistant_enabled; - if (NULL == func) { - MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_ENABLED); - } else { - ret = func(appid, enabled); - if (0 != ret) { - MAS_LOGE("[ERROR] Fail to set wakeup word(%s)(%d), ret(%d)", appid, enabled, ret); - } - } - } else { - MAS_LOGE("[ERROR] g_handle is not valid"); - } - return ret; -} - int multi_assistant_service_plugin_activate(void) { int ret = -1; -- 2.34.1