From: Ji-hoon Lee Date: Fri, 13 Dec 2019 11:25:34 +0000 (+0900) Subject: Restore assistant language configurations when activating X-Git-Tag: submit/tizen_5.5/20200409.014144~38 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1f6538bcd9c0916c0479a303058791d4018c3f6d;p=platform%2Fcore%2Fuifw%2Fmulti-assistant-service.git Restore assistant language configurations when activating Change-Id: Ia1f00b588bcf5b07a87f8b5598e31fd16d841c08 --- diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index 319a9eb..231db59 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -14,6 +14,7 @@ BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(capi-appfw-app-manager) BuildRequires: pkgconfig(capi-appfw-package-manager) BuildRequires: pkgconfig(capi-appfw-service-application) +BuildRequires: pkgconfig(capi-appfw-preference) BuildRequires: pkgconfig(capi-media-audio-io) BuildRequires: pkgconfig(capi-network-connection) BuildRequires: pkgconfig(dlog) diff --git a/plugins/wakeup-manager/CMakeLists.txt b/plugins/wakeup-manager/CMakeLists.txt index 55a8770..4e86c6c 100644 --- a/plugins/wakeup-manager/CMakeLists.txt +++ b/plugins/wakeup-manager/CMakeLists.txt @@ -16,6 +16,7 @@ SET(WMPKG_CHECK_MODULES ecore dlog capi-appfw-app-manager + capi-appfw-preference capi-network-connection capi-media-audio-io capi-media-sound-manager @@ -48,6 +49,7 @@ SET(SRCS src/wakeup_manager_wrapper.cpp src/dependency_resolver.cpp src/heap_tracer.cpp + src/assistant_config_manager.cpp ) FOREACH(flag ${wmpkgs_CFLAGS}) diff --git a/plugins/wakeup-manager/inc/assistant_config_manager.h b/plugins/wakeup-manager/inc/assistant_config_manager.h new file mode 100644 index 0000000..0dd7dda --- /dev/null +++ b/plugins/wakeup-manager/inc/assistant_config_manager.h @@ -0,0 +1,56 @@ +/* + * Copyright 2018-2019 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _ASSISTANT_CONFIG_MANAGER_H_ +#define _ASSISTANT_CONFIG_MANAGER_H_ + +#include +#include + +namespace multiassistant +{ +namespace wakeup +{ + +using namespace std; + +constexpr char LANGUAGE_PREFIX[] = "LANGUAGE_"; + +typedef void (*foreach_assistant_language_cb)(const char* appid, const char* language, void* user_data); + +class CAssistantConfigManager +{ +public: + CAssistantConfigManager(); + virtual ~CAssistantConfigManager(); + + CAssistantConfigManager(const CAssistantConfigManager&) = delete; + CAssistantConfigManager& operator=(const CAssistantConfigManager&) = delete; + + void initialize(); + void deinitialize(); + + int set_assistant_language(string assistant, string language); + int get_assistant_language(string assistant, string& language); + + void foreach_assistant_language(foreach_assistant_language_cb callback, void* user_data); +private: +}; + +} // wakeup +} // multiassistant + +#endif _ASSISTANT_CONFIG_MANAGER_H_ diff --git a/plugins/wakeup-manager/inc/wakeup_manager.h b/plugins/wakeup-manager/inc/wakeup_manager.h index f734256..b010453 100644 --- a/plugins/wakeup-manager/inc/wakeup_manager.h +++ b/plugins/wakeup-manager/inc/wakeup_manager.h @@ -23,6 +23,7 @@ #include "wakeup_engine_manager.h" #include "wakeup_audio_manager.h" #include "wakeup_policy_default.h" +#include "assistant_config_manager.h" #include #include @@ -204,6 +205,7 @@ private: CAudioManager mAudioManager; CWakeupEngineManager mWakeupEngineManager; CWakeupSettings mWakeupSettings; + CAssistantConfigManager mAssistantConfigManager; CAudioEventObserver mAudioEventObserver; CEngineEventObserver mEngineEventObserver; diff --git a/plugins/wakeup-manager/src/assistant_config_manager.cpp b/plugins/wakeup-manager/src/assistant_config_manager.cpp new file mode 100644 index 0000000..e15b411 --- /dev/null +++ b/plugins/wakeup-manager/src/assistant_config_manager.cpp @@ -0,0 +1,88 @@ +#include "assistant_config_manager.h" + +#include + +#include + +namespace multiassistant +{ +namespace wakeup +{ + +CAssistantConfigManager::CAssistantConfigManager() +{ +} + +CAssistantConfigManager::~CAssistantConfigManager() +{ +} + +void CAssistantConfigManager::initialize() +{ +} + +void CAssistantConfigManager::deinitialize() +{ +} + +int CAssistantConfigManager::set_assistant_language(string assistant, string language) +{ + string key = string{LANGUAGE_PREFIX} + assistant; + + preference_set_string(key.c_str(), language.c_str()); + + return 0; +} + +int CAssistantConfigManager::get_assistant_language(string assistant, string& language) +{ + string key = string{LANGUAGE_PREFIX} + assistant; + + bool existing = false; + preference_is_existing(key.c_str(), &existing); + if (!existing) return -1; + + char* value = nullptr; + preference_get_string(key.c_str(), &value); + if (nullptr == value) return -1; + + language = value; + free(value); + + return 0; +} + +void CAssistantConfigManager::foreach_assistant_language(foreach_assistant_language_cb callback, void* user_data) +{ + typedef struct { + foreach_assistant_language_cb callback; + void* user_data; + } foreach_assistant_language_cb_closure; + + foreach_assistant_language_cb_closure closure; + closure.callback = callback; + closure.user_data = user_data; + + preference_foreach_item( + [](const char *key, void *user_data) { + string prefix = string{LANGUAGE_PREFIX}; + foreach_assistant_language_cb_closure* closure = + static_cast(user_data); + if (key && strlen(key) > prefix.length() && + 0 == prefix.compare(0, prefix.length(), key, prefix.length())) { + char* value = nullptr; + preference_get_string(key, &value); + if (value) { + if (closure) { + closure->callback(key + prefix.length(), value, closure->user_data); + } + free(value); + } + } + return true; + }, static_cast(&closure) + ); +} + +} // wakeup +} // multiassistant diff --git a/plugins/wakeup-manager/src/wakeup_manager.cpp b/plugins/wakeup-manager/src/wakeup_manager.cpp index 095083a..c4e42cf 100644 --- a/plugins/wakeup-manager/src/wakeup_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_manager.cpp @@ -28,7 +28,11 @@ namespace wakeup static bool check_language_valid(string language) { - return true; + bool valid = true; + if (0 == language.length()) { + valid = false; + } + return valid; } static bool initialize_wakeup_event_info(mas_wakeup_event_info* wakeup_info) @@ -113,6 +117,8 @@ bool CWakeupManager::initialize() mWakeupEngineManager.subscribe(&mEngineEventObserver); mWakeupEngineManager.initialize(); + mAssistantConfigManager.initialize(); + mas_dependency_plugin_proxy_interface interface; interface.process_event = wakeup_manager_process_plugin_event; interface.feed_audio_data = wakeup_manager_feed_audio_data; @@ -133,6 +139,8 @@ bool CWakeupManager::deinitialize() dependency_resolver_deinitialize(); + mAssistantConfigManager.deinitialize(); + mWakeupEngineManager.unsubscribe(&mEngineEventObserver); mWakeupEngineManager.deinitialize(); @@ -261,6 +269,7 @@ bool CWakeupManager::set_assistant_language(string appid, string language) MWR_LOGD("[ENTER] : %s, %s", appid.c_str(), language.c_str()); mWakeupEngineManager.set_assistant_language(appid, language); + mAssistantConfigManager.set_assistant_language(appid, language); MWR_LOGD("[END]"); return true; @@ -318,45 +327,51 @@ bool CWakeupManager::get_assistant_enabled(string appid) bool CWakeupManager::set_language(string language) { - bool ret = false; + bool valid = false; MWR_LOGD("[ENTER] : %s", language.c_str()); if (check_language_valid(language)) { mCurrentLanguage = language; + valid = true; + } else { + MWR_LOGE("[ERROR] Invalid language (%s)", language.c_str()); + } - 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) { - mAssistantSupportsCurrentLanguage[info.appid] = false; - } else { - mAssistantSupportsCurrentLanguage[info.appid] = true; - } - - bool activated = found; - if (false == mAssistantEnabled[info.appid]) { - activated = false; - } - if (0 == info.appid.compare(mCurrentDefaultAssistant)) { - activated = true; + for (auto& info : mAssistantLanguageInfo) { + bool disable = false; + if (valid) { + bool supported = false; + if (info.languageList.end() != + find(info.languageList.begin(), info.languageList.end(), language)) { + supported = true; } - mWakeupEngineManager.set_assistant_activated(info.appid, activated); + mAssistantSupportsCurrentLanguage[info.appid] = supported; + /* Disable this assistant if language not supported */ + if (!supported) disable = true; + } else { + /* If current language is not valid, assume all languages support it */ + mAssistantSupportsCurrentLanguage[info.appid] = true; } - mWakeupEngineManager.set_language(language); - ret = true; - } else { - MWR_LOGE("[ERROR] Not supported language (%s)", language.c_str()); + if (false == mAssistantEnabled[info.appid]) { + disable = true; + } + if (0 == info.appid.compare(mCurrentDefaultAssistant)) { + /* Default Assistant should be activated no matter what */ + disable = false; + } + mWakeupEngineManager.set_assistant_activated(info.appid, !disable); + std::string assistant_language; + int ret = mAssistantConfigManager.get_assistant_language(info.appid, assistant_language); + if (0 != ret || !check_language_valid(assistant_language)) { + mWakeupEngineManager.set_assistant_language(info.appid, language); + } else { + mWakeupEngineManager.set_assistant_language(info.appid, assistant_language); + } } MWR_LOGD("[END]"); - return ret; + return valid; } bool CWakeupManager::get_voice_key_pressed()