multi-assistant
vconf
pkgmgr-info
+ jsoncpp
)
# SET FLAG ---------------------------------------------------------------------------------------
BuildRequires: pkgconfig(multi-assistant)
BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(pkgmgr-info)
+BuildRequires: pkgconfig(jsoncpp)
BuildRequires: boost-devel
%if %{defined _test_type}
BuildRequires: gtest-devel
vconf
pkgmgr-info
multi-assistant
+ jsoncpp
)
INCLUDE(FindPkgConfig)
EXPORT_API int mas_dependency_set_voice_key_tap_duration(float duration);
EXPORT_API int mas_dependency_unset_voice_key_tap_duration(void);
EXPORT_API int mas_dependency_set_voice_key_support_mode(const char* support_mode);
+EXPORT_API int mas_dependency_get_custom_vconf_key(const char* default_key, char** custom_key);
#ifdef __cplusplus
}
{
LOGD("support_mode : %s", support_mode);
return 0;
+}
+
+int mas_dependency_get_custom_vconf_key(const char* default_key, char** custom_key)
+{
+ return 0;
}
\ No newline at end of file
typedef int (*mas_dependency_unset_voice_key_tap_duration)(void);
#define MAS_DEPENDENCY_FUNC_SET_VOICE_KEY_SUPPORT_MODE "mas_dependency_set_voice_key_support_mode"
typedef int (*mas_dependency_set_voice_key_support_mode)(const char* support_mode);
+#define MAS_DEPENDENCY_FUNC_GET_CUSTOM_VCONF_KEY "mas_dependency_get_custom_vconf_key"
+typedef int (*mas_dependency_get_custom_vconf_key)(const char* default_key, char** custom_key);
typedef struct {
mas_dependency_set_voice_key_tap_duration set_voice_key_tap_duration;
mas_dependency_unset_voice_key_tap_duration unset_voice_key_tap_duration;
mas_dependency_set_voice_key_support_mode set_voice_key_support_mode;
+ mas_dependency_get_custom_vconf_key get_custom_vconf_key;
} mas_dependency_module_interface;
int dependency_resolver_initialize(mas_dependency_plugin_proxy_interface interface);
int dependency_resolver_set_voice_key_tap_duration(float duration);
int dependency_resolver_unset_voice_key_tap_duration();
int dependency_resolver_set_voice_key_support_mode(const char* support_mode);
+int dependency_resolver_get_custom_vconf_key(const char* default_key, char** custom_key);
mas_dependency_module_interface* dependency_resolver_get_interface();
using namespace std;
+#define WAKEUP_VCONF_KEY_DEFAULT_ASSISTANT_APPID "db/multi-assistant/default_assistant_appid"
+#define WAKEUP_VCONF_KEY_ENABLED_ASSISTANTS "db/multi-assistant/enabled_assistants"
+#define WAKEUP_VCONF_KEY_WAKE_WORD_DETECTION_ENABLED "db/multi-assistant/wake_word_detection_enabled"
+
enum class STREAMING_MODE {
NONE,
UTTERANCE,
bool on_assistant_enabled_info_changed(const char* appid, bool enabled) override;
bool on_default_assistant_appid_changed(const char* appid) override;
bool on_multiple_mode_changed() override;
+ bool on_wake_word_detection_enabled_info_changed() override;
void set_wakeup_manager(CWakeupManager *manager) { mWakeupManager = manager; }
private:
#include <string>
#include <vector>
#include <vconf.h>
+#include <map>
typedef void (*input_language_changed_cb)(void* data);
#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"
+#define WAKEUP_SETTINGS_KEY_WAKE_WORD_DETECTION_ENABLED "db/multi-assistant/wake_word_detection_enabled"
class ISettingsEventObserver
{
virtual bool on_assistant_enabled_info_changed(const char* appid, bool enabled) = 0;
virtual bool on_default_assistant_appid_changed(const char* appid) = 0;
virtual bool on_multiple_mode_changed() = 0;
+ virtual bool on_wake_word_detection_enabled_info_changed() = 0;
};
class CWakeupSettings
CWakeupSettings(const CWakeupSettings&) = delete;
CWakeupSettings& operator=(const CWakeupSettings&) = delete;
- void initialize();
+ void initialize(map<string, string> custom_keys);
void deinitialize();
void subscribe(ISettingsEventObserver *observer);
vector<string> get_wakeup_policy_priority();
float get_streaming_duration_max();
string get_current_language(void);
+ vector<string> get_wake_word_disabled_assistants();
private:
vector<ISettingsEventObserver*> mObservers;
vector<string> mWakeupPolicyPriority; // No priority by default
float mStreamingDurationMax{15.0};
string mVoiceInputLanguage;
+ map<string, string> mCustomVconfKeys;
+ vector<string> mWakeWordDisabledAssistants;
};
} // wakeup
g_mas_dependency.unset_voice_key_tap_duration =
(mas_dependency_unset_voice_key_tap_duration)dlsym(g_handle,
MAS_DEPENDENCY_FUNC_UNSET_VOICE_KEY_TAP_DURATION);
+ g_mas_dependency.set_voice_key_support_mode =
+ (mas_dependency_set_voice_key_support_mode)dlsym(g_handle,
+ MAS_DEPENDENCY_FUNC_SET_VOICE_KEY_SUPPORT_MODE);
+ g_mas_dependency.get_custom_vconf_key =
+ (mas_dependency_get_custom_vconf_key)dlsym(g_handle,
+ MAS_DEPENDENCY_FUNC_GET_CUSTOM_VCONF_KEY);
int ret = -1;
int dependency_version = 0;
}
return ret;
+}
+
+int dependency_resolver_get_custom_vconf_key(const char* default_key, char** custom_key)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ mas_dependency_get_custom_vconf_key func = g_mas_dependency.get_custom_vconf_key;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_GET_CUSTOM_VCONF_KEY);
+ } else {
+ try {
+ ret = func(default_key, custom_key);
+ } catch (const std::exception& e) {
+ MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+ MAS_DEPENDENCY_FUNC_GET_CUSTOM_VCONF_KEY, e.what());
+ }
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to get custom vconf key, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+
+ return ret;
}
\ No newline at end of file
#include <algorithm>
#include <iostream>
+#include <map>
#include <boost/optional.hpp>
return ret;
}
+static map<string, string> get_custom_vconf_keys()
+{
+ map<string, string> vconf_keys;
+ char* custom_key = NULL;
+
+ vconf_keys.clear();
+ dependency_resolver_get_custom_vconf_key(WAKEUP_VCONF_KEY_DEFAULT_ASSISTANT_APPID, &custom_key);
+ vconf_keys.insert({WAKEUP_VCONF_KEY_DEFAULT_ASSISTANT_APPID, custom_key ? custom_key : WAKEUP_VCONF_KEY_DEFAULT_ASSISTANT_APPID});
+
+ if (custom_key) {
+ free(custom_key);
+ custom_key = nullptr;
+ }
+
+ dependency_resolver_get_custom_vconf_key(WAKEUP_VCONF_KEY_ENABLED_ASSISTANTS, &custom_key);
+ vconf_keys.insert({WAKEUP_VCONF_KEY_ENABLED_ASSISTANTS, custom_key ? custom_key : WAKEUP_VCONF_KEY_ENABLED_ASSISTANTS});
+
+ if (custom_key) {
+ free(custom_key);
+ custom_key = nullptr;
+ }
+
+ dependency_resolver_get_custom_vconf_key(WAKEUP_VCONF_KEY_WAKE_WORD_DETECTION_ENABLED, &custom_key);
+ vconf_keys.insert({WAKEUP_VCONF_KEY_WAKE_WORD_DETECTION_ENABLED, custom_key ? custom_key : WAKEUP_VCONF_KEY_WAKE_WORD_DETECTION_ENABLED});
+
+ if (custom_key) {
+ free(custom_key);
+ custom_key = nullptr;
+ }
+
+ return vconf_keys;
+}
+
CWakeupManager::CWakeupManager(IWakeupEventObserver* wakeup_observer, ISettingValueObserver* setting_observer)
{
initialize_wakeup_event_info(&mLastWakeupEventInfo);
mAudioEventObserver.set_wakeup_manager(this);
mSettingsEventObserver.set_wakeup_manager(this);
+ mas_dependency_plugin_proxy_interface interface;
+ interface.process_event = wakeup_manager_process_plugin_event;
+ interface.feed_audio_data = wakeup_manager_feed_audio_data;
+ interface.send_command = wakeup_manager_set_dependency_module_command;
+ interface.wakeup_assistant = wakeup_manager_wakeup_assistant;
+
+ dependency_resolver_initialize(interface);
+
mWakeupSettings.subscribe(&mSettingsEventObserver);
- mWakeupSettings.initialize();
+ mWakeupSettings.initialize(get_custom_vconf_keys());
mAudioEventObserver.set_wakeup_engine_manager(&mWakeupEngineManager);
mAudioManager.subscribe(&mAudioEventObserver);
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;
- interface.send_command = wakeup_manager_set_dependency_module_command;
- interface.wakeup_assistant = wakeup_manager_wakeup_assistant;
-
- dependency_resolver_initialize(interface);
-
initialize_wakeup_policy();
start_periodic_monitor_timer();
{
MWR_LOGI("[ENTER] %s %s", appid.c_str(), engine.c_str());
+ vector<string> disabled_assistants = mWakeupSettings.get_wake_word_disabled_assistants();
+ auto iter = find(disabled_assistants.begin(), disabled_assistants.end(), appid);
+ if (iter != disabled_assistants.end())
+ return true;
+
bool found = false;
if (mWakeupSettings.get_multiple_mode()) {
vector<string> assistants = mWakeupSettings.get_enabled_assistants();
- auto iter = find(assistants.begin(), assistants.end(), appid);
+ iter = find(assistants.begin(), assistants.end(), appid);
if (iter != assistants.end())
found = true;
} else {
return true;
}
+bool CWakeupManager::CSettingsEventObserver::on_wake_word_detection_enabled_info_changed()
+{
+ if (nullptr == mWakeupManager) return false;
+ vector<ISettingValueObserver*> observers = mWakeupManager->get_setting_observers();
+ for (const auto& observer : observers) {
+ observer->on_loaded_wakeup_engine_changed();
+ }
+ return true;
+}
+
} // wakeup
} // multiassistant
#include <sstream>
#include <algorithm>
+#include <json/json.h>
namespace multiassistant
{
}
}
-void CWakeupSettings::initialize()
+static void wakeup_setting_enabled_wake_word_detection_changed_cb(keynode_t* node, void* data)
+{
+ MWR_LOGD("[ENTER]");
+
+ CWakeupSettings* settings = static_cast<CWakeupSettings*>(data);
+ if (nullptr == settings) return;
+
+ const auto& observers = settings->get_observers();
+ for (const auto& observer : observers) {
+ if (observer) {
+ if (!observer->on_wake_word_detection_enabled_info_changed()) {
+ LOGW("[Settings WARNING] One of the observer returned false");
+ }
+ }
+ }
+}
+
+void CWakeupSettings::initialize(map<string, string> custom_keys)
{
int vconf_ret;
char *vconf_str;
int vconf_bool;
double vconf_double;
- vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID);
+ mCustomVconfKeys.clear();
+ mCustomVconfKeys = custom_keys;
+
+ vconf_str = vconf_get_str(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID].c_str());
if (vconf_str) {
mDefaultAssistantAppid = vconf_str;
MWR_LOGD("default_assistant_appid : %s", mDefaultAssistantAppid.c_str());
MWR_LOGD("multiple_mode : %s", (mMultipleMode ? "true" : "false"));
}
if (true == mMultipleMode) {
- vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_ENABLED_ASSISTANTS);
+ vconf_str = vconf_get_str(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_ENABLED_ASSISTANTS].c_str());
if (vconf_str) {
string token;
istringstream iss(vconf_str);
vconf_str = nullptr;
}
}
+ vconf_str = vconf_get_str(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_WAKE_WORD_DETECTION_ENABLED].c_str());
+ if (vconf_str) {
+ Json::Reader reader;
+ Json::Value root;
+ mWakeWordDisabledAssistants.clear();
+ if (!reader.parse(vconf_str, root)) {
+ LOGW("[Settings WARNING] Failed to parse Json : %s", reader.getFormattedErrorMessages().c_str());
+ } else {
+ auto member = root.getMemberNames();
+ for (string m : member) {
+ if (0 == root[m].asString().compare("off")) {
+ mWakeWordDisabledAssistants.push_back(m);
+ MWR_LOGD("wake_word_detection_disabled assistant : %s", m.c_str());
+ }
+ }
+ }
+ free(vconf_str);
+ vconf_str = nullptr;
+ }
vconf_ret = vconf_get_dbl(WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_DELAY, &vconf_double);
if (0 == vconf_ret) {
mWakeupPolicyDelay = vconf_double;
vconf_notify_key_changed(WAKEUP_SETTINGS_KEY_VOICE_INPUT_LANGUAGE,
wakeup_setting_input_language_changed_cb, this);
- vconf_notify_key_changed(WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID,
+ vconf_notify_key_changed(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID].c_str(),
wakeup_setting_default_assistant_appid_changed_cb, this);
if (true == mMultipleMode) {
- vconf_notify_key_changed(WAKEUP_SETTINGS_KEY_ENABLED_ASSISTANTS,
+ vconf_notify_key_changed(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_ENABLED_ASSISTANTS].c_str(),
wakeup_setting_enabled_assistants_changed_cb, this);
}
vconf_notify_key_changed(WAKEUP_SETTINGS_KEY_MULTIPLE_MODE,
wakeup_setting_multiple_mode_changed_cb, this);
+ vconf_notify_key_changed(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_WAKE_WORD_DETECTION_ENABLED].c_str(),
+ wakeup_setting_enabled_wake_word_detection_changed_cb, this);
}
void CWakeupSettings::deinitialize()
{
vconf_ignore_key_changed(WAKEUP_SETTINGS_KEY_VOICE_INPUT_LANGUAGE,
wakeup_setting_input_language_changed_cb);
- vconf_ignore_key_changed(WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID,
+ vconf_ignore_key_changed(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID].c_str(),
wakeup_setting_default_assistant_appid_changed_cb);
if (true == mMultipleMode) {
- vconf_ignore_key_changed(WAKEUP_SETTINGS_KEY_ENABLED_ASSISTANTS,
+ vconf_ignore_key_changed(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_ENABLED_ASSISTANTS].c_str(),
wakeup_setting_enabled_assistants_changed_cb);
}
vconf_ignore_key_changed(WAKEUP_SETTINGS_KEY_MULTIPLE_MODE,
wakeup_setting_multiple_mode_changed_cb);
+ vconf_ignore_key_changed(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_WAKE_WORD_DETECTION_ENABLED].c_str(),
+ wakeup_setting_enabled_wake_word_detection_changed_cb);
}
void CWakeupSettings::subscribe(ISettingsEventObserver *observer)
string CWakeupSettings::get_default_assistant_appid()
{
char *vconf_str;
- vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID);
+ vconf_str = vconf_get_str(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID].c_str());
MWR_LOGD("vconf default_assistant_appid : %s", vconf_str);
if (vconf_str) {
mDefaultAssistantAppid = vconf_str;
MWR_LOGE("Default assistant appid not changed, ignoring...");
return;
}
- int ret = vconf_set_str(WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID, appid.c_str());
+ int ret = vconf_set_str(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID].c_str(), appid.c_str());
MWR_LOGD("default_assistant_appid : %s, %d", appid.c_str(), ret);
mDefaultAssistantAppid = appid;
}
return result;
}
+vector<string> CWakeupSettings::get_wake_word_disabled_assistants()
+{
+ return mWakeWordDisabledAssistants;
+}
+
} // wakeup
} // multiassistant