Modified not to load wakeup engine with wake_word_detection turned off
[platform/core/uifw/multi-assistant-service.git] / plugins / wakeup-manager / src / wakeup_settings.cpp
index bb90051..be28afe 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <sstream>
 #include <algorithm>
+#include <json/json.h>
 
 namespace multiassistant
 {
@@ -142,14 +143,34 @@ static void wakeup_setting_multiple_mode_changed_cb(keynode_t* node, void* data)
        }
 }
 
-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());
@@ -179,7 +200,7 @@ void CWakeupSettings::initialize()
                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);
@@ -199,6 +220,25 @@ void CWakeupSettings::initialize()
                        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;
@@ -238,28 +278,32 @@ void CWakeupSettings::initialize()
 
        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)
@@ -283,7 +327,7 @@ const vector<ISettingsEventObserver*>& CWakeupSettings::get_observers()
 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;
@@ -301,7 +345,7 @@ void CWakeupSettings::set_default_assistant_appid(std::string appid)
                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;
 }
@@ -352,5 +396,10 @@ std::string CWakeupSettings::get_current_language(void)
        return result;
 }
 
+vector<string> CWakeupSettings::get_wake_word_disabled_assistants()
+{
+       return mWakeWordDisabledAssistants;
+}
+
 } // wakeup
 } // multiassistant