Support multiple wakeup engines for single assistant 84/262084/1
authorJi-hoon Lee <dalton.lee@samsung.com>
Thu, 29 Apr 2021 08:19:04 +0000 (17:19 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Mon, 2 Aug 2021 15:03:18 +0000 (00:03 +0900)
Change-Id: I417c1692707274eb2a727151f446fa6f170475e7

14 files changed:
inc/client_info.h
inc/service_common.h
inc/service_config.h
inc/service_plugin.h
inc/service_plugin_interface.h
plugins/wakeup-manager/inc/wakeup_manager.h
plugins/wakeup-manager/inc/wakeup_manager_wrapper.h
plugins/wakeup-manager/src/wakeup_engine_manager.cpp
plugins/wakeup-manager/src/wakeup_manager.cpp
plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp
src/package_update_monitor.cpp
src/service_config.cpp
src/service_main.cpp
src/service_plugin.cpp

index d2de5a81f0d7a74472c8089ab59e1b0102d36516..fd6da21e6f623f23f0fd30fb9e07e23395e5bdfa 100644 (file)
@@ -30,7 +30,7 @@ typedef struct {
        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 wakeup_engine[MAX_WAKEUP_ENGINES_NUM][MAX_APPID_LEN];
        char supported_language[MAX_SUPPORTED_LANGUAGES_NUM][MAX_SUPPORTED_LANGUAGE_LEN];
        bool custom_ui_option{false};
        VOICE_KEY_SUPPORT_MODE voice_key_support_mode{VOICE_KEY_SUPPORT_MODE_PUSH_TO_TALK};
index 3da1e46872e50b969fa7ca6c38956c9e7a0a67b3..f65062596677ffca98890f249e5d9255e5c4d1c3 100644 (file)
@@ -124,6 +124,7 @@ typedef void (*wakeup_service_voice_key_status_changed_cb)(ma_voice_key_status_e
 #define MAX_WAKEUP_WORD_LEN 32
 #define MAX_SUPPORTED_LANGUAGES_NUM 255
 #define MAX_SUPPORTED_LANGUAGE_LEN 16
+#define MAX_WAKEUP_ENGINES_NUM 4
 
 #define MAX_APPID_LEN 255
 
index 6ce7607792624c45de16e1a5db1f5ce9520488c2..ace3a2a0cd3fb90d5459d062446307664ddf773c 100644 (file)
@@ -37,6 +37,7 @@
 #define MA_TAG_ASSISTANT_LANGUAGE                              "language"
 #define MA_TAG_ASSISTANT_WAKEUP_WORD_SET               "wakeup-words"
 #define MA_TAG_ASSISTANT_WAKEUP_WORD                   "wakeup-word"
+#define MA_TAG_ASSISTANT_WAKEUP_ENGINE_SET             "wakeup-engines"
 #define MA_TAG_ASSISTANT_WAKEUP_ENGINE_APPID   "wakeup-engine-appid"
 #define MA_TAG_ASSISTANT_CUSTOM_UI                             "custom-ui"
 #define MA_TAG_ASSISTANT_VOICE_KEY_SUPPORT_MODE        "voice-key-support-mode"
@@ -65,7 +66,8 @@ typedef struct ma_assistant_info_s {
                cnt_wakeup{0},
                supported_lang{0x00, },
                cnt_lang{0},
-               wakeup_engine{nullptr},
+               wakeup_engine{nullptr, },
+               cnt_wakeup_engine{0},
                custom_ui_option{false},
                /* TODO: Define these two default values somewhere else */
                voice_key_support_mode{VOICE_KEY_SUPPORT_MODE_PUSH_TO_TALK},
@@ -80,7 +82,8 @@ typedef struct ma_assistant_info_s {
        int cnt_wakeup;
        const char* supported_lang[MAX_SUPPORTED_LANGUAGES_NUM];
        int cnt_lang;
-       const char* wakeup_engine;
+       const char* wakeup_engine[MAX_WAKEUP_ENGINES_NUM];
+       int cnt_wakeup_engine;
        bool custom_ui_option;
        VOICE_KEY_SUPPORT_MODE voice_key_support_mode;
        float voice_key_tap_duration;
index a3ed80499e9a0375fe66c4d18a52a8a32739339c..112a9cb33387fe08308585e83cd915e4b63d2e4e 100644 (file)
@@ -38,7 +38,7 @@ public:
        int add_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language);
        int remove_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language);
        int add_assistant_language(const char* appid, const char* language);
-       int set_assistant_wakeup_engine(const char* appid, const char* engine);
+       int add_assistant_wakeup_engine(const char* appid, const char* engine);
        int set_default_assistant(const char* appid);
        int get_default_assistant(const char** appid);
        int activate(void);
index 944a9670ae9b750b45fc7b1cdda0004071dc9111..1cd8d35be3176575ff361b606611dd57425f4e6b 100644 (file)
@@ -41,8 +41,8 @@ typedef int (*wakeup_manager_add_assistant_wakeup_word)(const char* appid, const
 typedef int (*wakeup_manager_remove_assistant_wakeup_word)(const char* appid, const char* wakeup_word, const char* language);
 #define MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE "wakeup_manager_add_assistant_language"
 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_ADD_ASSISTANT_WAKEUP_ENGINE "wakeup_manager_add_assistant_wakeup_engine"
+typedef int (*wakeup_manager_add_assistant_wakeup_engine)(const char* appid, const char* engine);
 #define MA_WAKEUP_MANAGER_FUNC_SET_DEFAULT_ASSISTANT "wakeup_manager_set_default_assistant"
 typedef int (*wakeup_manager_set_default_assistant)(const char* appid);
 #define MA_WAKEUP_MANAGER_FUNC_GET_DEFAULT_ASSISTANT "wakeup_manager_get_default_assistant"
@@ -119,7 +119,7 @@ typedef struct {
        wakeup_manager_add_assistant_wakeup_word                                        add_assistant_wakeup_word;
        wakeup_manager_remove_assistant_wakeup_word                                     remove_assistant_wakeup_word;
        wakeup_manager_add_assistant_language                                           add_assistant_language;
-       wakeup_manager_set_assistant_wakeup_engine                                      set_assistant_wakeup_engine;
+       wakeup_manager_add_assistant_wakeup_engine                                      add_assistant_wakeup_engine;
        wakeup_manager_set_default_assistant                                            set_default_assistant;
        wakeup_manager_get_default_assistant                                            get_default_assistant;
        wakeup_manager_set_language                                                                     set_language;
index dc2cbad3f6de4e9e35e425f0dd64ddf295b87433..657c3ec5f8e3237037766b726cc4445df261af1d 100644 (file)
@@ -90,7 +90,7 @@ public:
        bool add_assistant_language(string appid, string language);
        bool add_assistant_wakeup_word(string appid, string wakeup_word, string language);
        bool remove_assistant_wakeup_word(string appid, string wakeup_word, string language);
-       bool set_assistant_wakeup_engine(string appid, string engine);
+       bool add_assistant_wakeup_engine(string appid, string engine);
        bool set_assistant_language(string appid, string language);
 
        bool set_assistant_enabled(string appid, bool enabled);
index 45ac5678cc028fb789d09667e73b6fcdc40997d8..3ee305f6c830dbf3d100cba231c108e8d6e39a4c 100644 (file)
@@ -77,7 +77,7 @@ EXPORT_API int wakeup_manager_remove_assistant_wakeup_word(const char* appid, co
 
 EXPORT_API int wakeup_manager_add_assistant_language(const char* appid, const char* language);
 
-EXPORT_API int wakeup_manager_set_assistant_wakeup_engine(const char* appid, const char *engine);
+EXPORT_API int wakeup_manager_add_assistant_wakeup_engine(const char* appid, const char *engine);
 
 EXPORT_API int wakeup_manager_set_default_assistant(const char* appid);
 
index 56c06ca85857c41b2466170435219f388773a193..b458553e7f4636d93e8ca62c2fcca79558fe07a4 100644 (file)
@@ -224,6 +224,7 @@ void CWakeupEngineManager::set_assistant_activated(string appid, bool activated)
 
                /* If the appid is in the assistant list */
                if (info.assistant_list.end() != iter) {
+                       MWR_LOGI("%s has %s", info.engine_name.c_str(), appid.c_str());
                        bool previously_activated = info.activated;
                        if (activated) {
                                info.activated_assistants.insert(appid);
@@ -250,6 +251,8 @@ void CWakeupEngineManager::set_assistant_activated(string appid, bool activated)
                                /* Activated status changed, need to update audio_data_require_status too */
                                on_audio_data_require_status(info.engine_name, info.audio_data_require_status);
                        }
+               } else {
+                       MWR_LOGI("%s does not have %s", info.engine_name.c_str(), appid.c_str());
                }
        }
 }
@@ -558,9 +561,15 @@ void CWakeupEngineManager::engine_add_target_assistant(string engine_name, strin
                if (mEngineInfo.end() != new_iter) {
                        new_iter->assistant_list.push_back(appid);
                }
+               for (const auto assistant : new_iter->assistant_list) {
+                       MWR_LOGI("Assistant List : %s %s", assistant.c_str(), new_iter->engine_name.c_str());
+               }
        } else {
                /* If the engine already exists, simply add the appid to the assistant list */
                iter->assistant_list.push_back(appid);
+               for (const auto assistant : iter->assistant_list) {
+                       MWR_LOGI("Assistant List : %s %s", assistant.c_str(), iter->engine_name.c_str());
+               }
        }
 }
 
index 5399c7835586812add2e6e0150db1cbabeed9a61..7f856ea2772b6d81b509a98d444570e1577045a6 100644 (file)
@@ -266,9 +266,9 @@ bool CWakeupManager::remove_assistant_wakeup_word(string appid, string wakeup_wo
        return true;
 }
 
-bool CWakeupManager::set_assistant_wakeup_engine(string appid, string engine)
+bool CWakeupManager::add_assistant_wakeup_engine(string appid, string engine)
 {
-       MWR_LOGI("[ENTER]");
+       MWR_LOGI("[ENTER] %s %s", appid.c_str(), engine.c_str());
 
        mWakeupEngineManager.engine_add_target_assistant(engine, appid);
 
index d88dd345b9e512a3b0f4ddc3ee2d69373816253d..9dd7ef2fb6e52215b45b21380c39a6a864313f93 100644 (file)
@@ -224,7 +224,7 @@ int wakeup_manager_add_assistant_language(const char* appid, const char* languag
        return 0;
 }
 
-int wakeup_manager_set_assistant_wakeup_engine(const char* appid, const char* engine)
+int wakeup_manager_add_assistant_wakeup_engine(const char* appid, const char* engine)
 {
        MWR_LOGI("[ENTER]");
 
@@ -235,7 +235,7 @@ int wakeup_manager_set_assistant_wakeup_engine(const char* appid, const char* en
 
        if (nullptr == g_wakeup_manager) return -1;
        MWR_LOGD("[DEBUG] appid(%s), wakeup engine(%s)", appid, engine);
-       g_wakeup_manager->set_assistant_wakeup_engine(string{appid}, string{engine});
+       g_wakeup_manager->add_assistant_wakeup_engine(string{appid}, string{engine});
 
        MWR_LOGD("[END]");
        return 0;
index 1a57bd89f28b32c9827b8613da22ff0430f60cfe..db2d16e9c42acdc5bb8d005689a242f6d37825ae 100644 (file)
@@ -73,9 +73,11 @@ static bool is_wakeup_engine(const pkgmgrinfo_appinfo_h handle, CPackageUpdateMo
        if (PMINFO_R_OK == ret && NULL != appid) {
                for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM;loop++) {
                        if (clientInfo.getItems()[loop].used) {
-                               LOGD("comparing appid : %s %s", clientInfo.getItems()[loop].wakeup_engine, appid);
-                               if (0 == strncmp(clientInfo.getItems()[loop].wakeup_engine, appid, MAX_APPID_LEN)) {
-                                       is_wakeup_engine = true;
+                               for (int inner_loop; inner_loop < MAX_WAKEUP_ENGINES_NUM;inner_loop++) {
+                                       LOGD("comparing appid : %s %s", clientInfo.getItems()[loop].wakeup_engine[inner_loop], appid);
+                                       if (0 == strncmp(clientInfo.getItems()[loop].wakeup_engine[inner_loop], appid, MAX_APPID_LEN)) {
+                                               is_wakeup_engine = true;
+                                       }
                                }
                        }
                }
index cdf1687b54e8b686d20d54b56db49fb1e32df83e..d7974809c975657dbf31a172ac703161e6fd05b8 100644 (file)
@@ -128,12 +128,38 @@ int CServiceConfig::parse_assistant_info(service_config_assistant_info_cb callba
                                MAS_LOGD("Icon Path : %s", key);
                                xmlFree(key);
                        }
+               /* For supporting previous version of schema - START */
                } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_WAKEUP_ENGINE_APPID)) {
-                       key = xmlNodeGetContent(cur);
-                       if (key) {
-                               temp.wakeup_engine = strdup((const char*)key);
-                               MAS_LOGD("Wakeup Engine : %s", key);
-                               xmlFree(key);
+                       if (temp.cnt_wakeup_engine == 0) {
+                               key = xmlNodeGetContent(cur);
+                               if (key) {
+                                       temp.wakeup_engine[0] = strdup((const char*)key);
+                                       MAS_LOGD("Wakeup Engine : %s", key);
+                                       xmlFree(key);
+                               }
+                               temp.cnt_wakeup_engine = 1;
+                       } else {
+                               MAS_LOGE("wakeup engine appid with cnt_wakeup_engine (%d) found", temp.cnt_wakeup_engine);
+                       }
+               /* For supporting previous version of schema - END */
+               } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar *)MA_TAG_ASSISTANT_WAKEUP_ENGINE_SET)) {
+                       xmlNodePtr child_node = cur->xmlChildrenNode;
+                       while (child_node != NULL) {
+                               if (child_node->name && 0 == xmlStrcmp(child_node->name, (const xmlChar*)MA_TAG_ASSISTANT_WAKEUP_ENGINE_APPID)) {
+                                       key = xmlNodeGetContent(child_node);
+                                       if (key) {
+                                               temp.wakeup_engine[temp.cnt_wakeup_engine] = strdup((const char*)key);
+                                               MAS_LOGD("Wakeup Engine : %s", key);
+                                               xmlFree(key);
+                                       }
+                                       temp.cnt_wakeup_engine++;
+                                       if (temp.cnt_wakeup_engine >= MAX_WAKEUP_ENGINES_NUM) {
+                                               MAS_LOGE("cnt_wakeup_engine exceeds : %d", MAX_WAKEUP_ENGINES_NUM);
+                                               temp.cnt_wakeup_engine = MAX_WAKEUP_ENGINES_NUM - 1;
+                                       }
+                               }
+
+                               child_node = child_node->next;
                        }
                } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_CUSTOM_UI)) {
                        key = xmlNodeGetContent(cur);
@@ -200,8 +226,10 @@ int CServiceConfig::parse_assistant_info(service_config_assistant_info_cb callba
                        free((void*)(temp.supported_lang[loop]));
                }
        }
-       if (temp.wakeup_engine) {
-               free((void*)temp.wakeup_engine);
+       for (loop = 0; loop < temp.cnt_wakeup_engine; loop++) {
+               if (temp.wakeup_engine[loop]) {
+                       free((void*)(temp.wakeup_engine[loop]));
+               }
        }
 
        xmlFreeDoc(doc);
index b37b422a44f170a6f6d747455400bea9ec0477d4..8d0d1d2ef01ad59d8225b0c0fd07b004a9b3cbb4 100644 (file)
@@ -602,13 +602,15 @@ int CServiceMain::add_assistant_info(ma_assistant_info_s* info) {
                        }
                }
 
-               MAS_LOGD("wakeup_engine(%s)", info->wakeup_engine);
-               if (info->wakeup_engine) {
-                       strncpy(items[index].wakeup_engine, info->wakeup_engine, MAX_APPID_LEN);
-                       items[index].wakeup_engine[MAX_APPID_LEN - 1] = '\0';
-               } else {
-                       items[index].wakeup_engine[0] = '\0';
-                       MAS_LOGW("Wakeup engine information not provided for : %s", info->app_id);
+               for (loop = 0;loop < MAX_WAKEUP_ENGINES_NUM;loop++) {
+                       if (loop < info->cnt_wakeup_engine && info->wakeup_engine[loop]) {
+                               MAS_LOGD("wakeup_engine(%s)", info->wakeup_engine[loop]);
+                               strncpy(items[index].wakeup_engine[loop], info->wakeup_engine[loop], MAX_APPID_LEN);
+                               items[index].wakeup_engine[loop][MAX_APPID_LEN - 1] = '\0';
+                       } else {
+                               items[index].wakeup_engine[loop][0] = '\0';
+                               MAS_LOGW("Wakeup engine information not provided for : %s", info->app_id);
+                       }
                }
                items[index].custom_ui_option = info->custom_ui_option;
 
@@ -682,10 +684,12 @@ int CServiceMain::initialize_service_plugin(void)
                        if (0 < strlen(items[loop].appid)) {
                                mServiceConfig.load_custom_wake_words(items[loop].appid,
                                        items[loop].wakeup_word, items[loop].wakeup_language);
-                               if (0 < strlen(items[loop].wakeup_engine)) {
-                                       mServicePlugin.set_assistant_wakeup_engine(
-                                               items[loop].appid,
-                                               items[loop].wakeup_engine);
+                               for (inner_loop = 0; inner_loop < MAX_WAKEUP_ENGINES_NUM; inner_loop++) {
+                                       if (0 < strlen(items[loop].wakeup_engine[inner_loop])) {
+                                               mServicePlugin.add_assistant_wakeup_engine(
+                                                       items[loop].appid,
+                                                       items[loop].wakeup_engine[inner_loop]);
+                                       }
                                }
                                for (inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
                                        if (0 < strlen(items[loop].wakeup_word[inner_loop])) {
@@ -1244,9 +1248,11 @@ bool CServiceMain::is_valid_wakeup_engine(const char* appid)
        for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM;loop++) {
                ClientInfoItems *items = mClientInfo.getItems();
                if (items[loop].used) {
-                       LOGD("comparing appid : %s %s", items[loop].wakeup_engine, appid);
-                       if (0 == strncmp(items[loop].wakeup_engine, appid, MAX_APPID_LEN)) {
-                               return true;
+                       for (int inner_loop; inner_loop < MAX_WAKEUP_ENGINES_NUM;inner_loop++) {
+                               LOGD("comparing appid : %s %s", items[loop].wakeup_engine[inner_loop], appid);
+                               if (0 == strncmp(items[loop].wakeup_engine[inner_loop], appid, MAX_APPID_LEN)) {
+                                       return true;
+                               }
                        }
                }
        }
index 6f820c65ab1d26cf3b57a8a8acef0654f6e54b30..7c96d40461b0502de56d2c34199c5b697cb6bc59 100644 (file)
@@ -560,9 +560,9 @@ int CServicePlugin::initialize(void)
        mWakeupManagerInterface.add_assistant_language =
                (wakeup_manager_add_assistant_language)dlsym(mPluginHandle,
                MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE);
-       mWakeupManagerInterface.set_assistant_wakeup_engine =
-               (wakeup_manager_set_assistant_wakeup_engine)dlsym(mPluginHandle,
-               MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE);
+       mWakeupManagerInterface.add_assistant_wakeup_engine =
+               (wakeup_manager_add_assistant_wakeup_engine)dlsym(mPluginHandle,
+               MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_ENGINE);
        mWakeupManagerInterface.set_default_assistant =
                (wakeup_manager_set_default_assistant)dlsym(mPluginHandle,
                MA_WAKEUP_MANAGER_FUNC_SET_DEFAULT_ASSISTANT);
@@ -824,13 +824,13 @@ int CServicePlugin::add_assistant_language(const char* appid, const char* langua
        return ret;
 }
 
-int CServicePlugin::set_assistant_wakeup_engine(const char* appid, const char* engine)
+int CServicePlugin::add_assistant_wakeup_engine(const char* appid, const char* engine)
 {
        int ret = -1;
        if (NULL != mPluginHandle) {
-               wakeup_manager_set_assistant_wakeup_engine func = mWakeupManagerInterface.set_assistant_wakeup_engine;
+               wakeup_manager_add_assistant_wakeup_engine func = mWakeupManagerInterface.add_assistant_wakeup_engine;
                if (NULL == func) {
-                       MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE);
+                       MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_ENGINE);
                } else {
                        ret = func(appid, engine);
                        if (0 != ret) {