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)
ecore
dlog
capi-appfw-app-manager
+ capi-appfw-preference
capi-network-connection
capi-media-audio-io
capi-media-sound-manager
src/wakeup_manager_wrapper.cpp
src/dependency_resolver.cpp
src/heap_tracer.cpp
+ src/assistant_config_manager.cpp
)
FOREACH(flag ${wmpkgs_CFLAGS})
--- /dev/null
+/*
+ * 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 <string>
+#include <functional>
+
+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_
#include "wakeup_engine_manager.h"
#include "wakeup_audio_manager.h"
#include "wakeup_policy_default.h"
+#include "assistant_config_manager.h"
#include <memory>
#include <map>
CAudioManager mAudioManager;
CWakeupEngineManager mWakeupEngineManager;
CWakeupSettings mWakeupSettings;
+ CAssistantConfigManager mAssistantConfigManager;
CAudioEventObserver mAudioEventObserver;
CEngineEventObserver mEngineEventObserver;
--- /dev/null
+#include "assistant_config_manager.h"
+
+#include <string.h>
+
+#include <app_preference.h>
+
+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<foreach_assistant_language_cb_closure*>(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<void*>(&closure)
+ );
+}
+
+} // wakeup
+} // multiassistant
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)
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;
dependency_resolver_deinitialize();
+ mAssistantConfigManager.deinitialize();
+
mWakeupEngineManager.unsubscribe(&mEngineEventObserver);
mWakeupEngineManager.deinitialize();
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;
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()