char wakeup_engine[MAX_APPID_LEN];
char supported_language[MAX_SUPPORTED_LANGUAGES_NUM][MAX_SUPPORTED_LANGUAGE_LEN];
bool custom_ui_option;
+
+ ma_preprocessing_allow_mode_e preprocessing_allow_mode;
+ char preprocessing_allow_appid[MAX_APPID_LEN];
} ma_client_info;
static ma_client_info g_maclient_info[MAX_MACLIENT_INFO_NUM];
static int g_current_maclient_info = 0;
static const char *g_wakeup_maclient_appid = NULL;
+static PREPROCESSING_STATE g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
+
/* client list */
static GSList* g_client_list = NULL;
return NULL;
}
+bool check_preprocessing_assistant_exists()
+{
+ bool ret = false;
+
+ char* vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
+ if (vconf_str) {
+ for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
+ if (g_maclient_info[loop].used && g_maclient_info[loop].appid) {
+ if (strncmp(vconf_str, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
+ ret = true;
+ }
+ }
+ }
+ free(vconf_str);
+ vconf_str = NULL;
+ }
+
+ return ret;
+}
+
+bool is_current_preprocessing_assistant(const char* appid)
+{
+ if (NULL == appid) return false;
+
+ bool ret = false;
+
+ char* vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
+ if (vconf_str) {
+ if (strncmp(vconf_str, appid, MAX_APPID_LEN) == 0) {
+ ret = true;
+ }
+ free(vconf_str);
+ vconf_str = NULL;
+ }
+
+ return ret;
+}
+
int mas_client_initialize(int pid)
{
MAS_LOGD("[Enter] pid(%d)", pid);
g_wakeup_maclient_appid = NULL;
mas_client_send_preprocessing_information(pid);
mas_client_activate(pid);
+ mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ACTIVE_ASSISTANT_LAUNCHED);
} else {
MAS_LOGE("[ERROR] g_wakeup_maclient_appid and appid differ : %s %s",
(g_wakeup_maclient_appid ? g_wakeup_maclient_appid : "NULL"), appid);
int ret = -1;
MAS_LOGD("[Enter] pid(%d)", pid);
- if (check_pid_is_current_maclient(pid)) {
- MAS_LOGD("pid %d matches with current MA Client, activating", pid);
- ret = masc_dbus_active_state_change(pid, MA_ACTIVE_STATE_ACTIVE);
- }
+ ret = masc_dbus_active_state_change(pid, MA_ACTIVE_STATE_ACTIVE);
+
+ return ret;
+}
+
+int mas_client_deactivate(int pid)
+{
+ int ret = -1;
+ MAS_LOGD("[Enter] pid(%d)", pid);
+
+ ret = masc_dbus_active_state_change(pid, MA_ACTIVE_STATE_INACTIVE);
return ret;
}
switch(type) {
case MA_AUDIO_STREAMING_DATA_TYPE_CURRENT_UTTERANCE:
ret = multi_assistant_service_plugin_start_streaming_utterance_data();
+ mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED);
break;
case MA_AUDIO_STREAMING_DATA_TYPE_PREVIOUS_UTTERANCE:
ret = multi_assistant_service_plugin_start_streaming_previous_utterance_data();
+ /* Preprocessing is not required for previous utterance streaming */
break;
case MA_AUDIO_STREAMING_DATA_TYPE_FOLLOW_UP_SPEECH:
ret = multi_assistant_service_plugin_start_streaming_follow_up_data();
+ mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED);
break;
}
return ret;
return 0;
}
+int mas_client_set_preprocessing_allow_mode(int pid, int mode, const char* appid)
+{
+ const char* pid_appid = NULL;
+ char buf[MAX_APPID_LEN] = {'\0',};
+ if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) {
+ buf[MAX_APPID_LEN - 1] = '\0';
+ pid_appid = buf;
+ }
+
+ for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
+ if (g_maclient_info[loop].used && g_maclient_info[loop].appid) {
+ if (strncmp(pid_appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
+ g_maclient_info[loop].preprocessing_allow_mode = mode;
+ strncpy(g_maclient_info[loop].preprocessing_allow_appid, appid, MAX_APPID_LEN);
+ g_maclient_info[loop].preprocessing_allow_appid[MAX_APPID_LEN - 1] = '\0';
+ }
+ }
+ }
+
+ mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_ALLOW_MODE_CHANGED);
+
+ return 0;
+}
+
int mas_client_update_recognition_result(int pid, int state)
{
multi_assistant_service_plugin_update_recognition_result(NULL, state);
mas_set_current_client_by_appid(appid);
int pid = mas_get_client_pid_by_appid(appid);
if (pid != -1) {
- /* Bring MA client to foreground - is there a better way instead of launching? */
- mas_launch_client_by_appid(appid, CLIENT_LAUNCH_MODE_ACTIVATION);
+ mas_bring_client_to_foreground(appid);
mas_client_send_preprocessing_information(pid);
- masc_dbus_active_state_change(pid, MA_ACTIVE_STATE_ACTIVE);
+ mas_client_activate(pid);
MAS_LOGD("MA Client with appid %s exists, requesting speech data", (appid ? appid : "NULL"));
/*
int ret = multi_assistant_service_plugin_start_streaming_utterance_data();
}
if (-1 != index) {
g_maclient_info[index].used = true;
+ g_maclient_info[index].preprocessing_allow_mode = MA_PREPROCESSING_ALLOW_NONE;
+ g_maclient_info[index].preprocessing_allow_appid[0] = '\0';
MAS_LOGD("app_id(%s)", appid);
strncpy(g_maclient_info[index].appid, appid, MAX_APPID_LEN);
g_maclient_info[index].appid[MAX_APPID_LEN - 1] = '\0';
if (g_current_maclient_info != prev_selection) {
if (prev_selection >= 0 && prev_selection < MAX_MACLIENT_INFO_NUM) {
- masc_dbus_active_state_change(
- mas_get_client_pid_by_appid(g_maclient_info[prev_selection].appid),
- MA_ACTIVE_STATE_INACTIVE);
+ mas_client_deactivate(mas_get_client_pid_by_appid(g_maclient_info[prev_selection].appid));
}
}
if (g_current_maclient_info != prev_selection) {
if (prev_selection >= 0 && prev_selection < MAX_MACLIENT_INFO_NUM) {
- masc_dbus_active_state_change(
- mas_get_client_pid_by_appid(g_maclient_info[prev_selection].appid),
- MA_ACTIVE_STATE_INACTIVE);
+ mas_client_deactivate(mas_get_client_pid_by_appid(g_maclient_info[prev_selection].appid));
}
}
return -1;
}
- int result;
- if (CLIENT_LAUNCH_MODE_PRELAUNCH == launch_mode) {
- result = aul_svc_set_background_launch(b, TRUE);
- if (result < AUL_R_OK) {
- MAS_LOGE("ERROR : aul_svc_set_background_launch failed. app_id [%s] bundle[%p] result[%d : %s]",
- appid, b, result, get_error_message(result));
- }
+ int result = aul_svc_set_background_launch(b, TRUE);
+ if (result < AUL_R_OK) {
+ MAS_LOGE("ERROR : aul_svc_set_background_launch failed. app_id [%s] bundle[%p] result[%d : %s]",
+ appid, b, result, get_error_message(result));
}
result = aul_launch_app(appid, b);
return result;
}
+int mas_bring_client_to_foreground(const char* appid)
+{
+ /* Bring MA client to foreground - is there a better way other than launching? */
+ if (NULL == appid || 0 == strlen(appid)) {
+ MAS_LOGE("appid invalid, failed launching MA Client");
+ return -1;
+ }
+
+ bundle *b = NULL;
+ b = bundle_create();
+ if (NULL == b) {
+ MAS_LOGE("Failed creating bundle for aul operation");
+ return -1;
+ }
+
+ int result = aul_launch_app(appid, b);
+ if (result < AUL_R_OK) {
+ MAS_LOGE("ERROR : aul_launch_app failed. app_id [%s] bundle[%p] result[%d : %s]",
+ appid, b, result, get_error_message(result));
+ }
+
+ if (b) bundle_free(b);
+ b = NULL;
+
+ return result;
+}
+
int mas_launch_client_by_wakeup_word(const char *wakeup_word)
{
const char *appid = mas_get_client_appid_by_wakeup_word(wakeup_word);
return 0;
}
+ma_preprocessing_allow_mode_e get_preprocessing_allow_mode(const char* appid)
+{
+ for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
+ if (g_maclient_info[loop].used && g_maclient_info[loop].appid) {
+ if (strncmp(appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
+ return g_maclient_info[loop].preprocessing_allow_mode;
+ }
+ }
+ }
+ return MA_PREPROCESSING_ALLOW_NONE;
+}
+
+int mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT event)
+{
+ const char* current_maclient_appid = NULL;
+ const char* preprocessing_allow_appid = NULL;
+ if (g_current_maclient_info >= 0 && g_current_maclient_info < MAX_MACLIENT_INFO_NUM) {
+ current_maclient_appid = g_maclient_info[g_current_maclient_info].appid;
+ preprocessing_allow_appid = g_maclient_info[g_current_maclient_info].preprocessing_allow_appid;
+ }
+ ma_preprocessing_allow_mode_e mode = get_preprocessing_allow_mode(current_maclient_appid);
+
+ switch (event) {
+ case PREPROCESSING_STATE_EVENT_WAKEUP:
+ case PREPROCESSING_STATE_EVENT_ACTIVE_ASSISTANT_LAUNCHED:
+ {
+ if (!check_preprocessing_assistant_exists()) {
+ mas_bring_client_to_foreground(current_maclient_appid);
+ }
+ }
+ /* Intentionally omitted break statement here */
+ case PREPROCESSING_STATE_EVENT_PREPROCESSING_ALLOW_MODE_CHANGED:
+ {
+ g_current_preprocessing_state = PREPROCESSING_STATE_WAKEUP_PREPROCESS_DISABLED;
+ if (MA_PREPROCESSING_ALLOW_UTTERANCE == mode ||
+ MA_PREPROCESSING_ALLOW_ALL == mode) {
+ if (is_current_preprocessing_assistant(preprocessing_allow_appid)) {
+ g_current_preprocessing_state = PREPROCESSING_STATE_WAKEUP_PREPROCESS_ENABLED;
+ }
+ }
+ }
+ break;
+ case PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED:
+ {
+ if (PREPROCESSING_STATE_WAKEUP_PREPROCESS_ENABLED == g_current_preprocessing_state) {
+ g_current_preprocessing_state = PREPROCESSING_STATE_PREPROCESSING_UTTERANCE;
+ } else if (PREPROCESSING_STATE_WAKEUP_PREPROCESS_DISABLED == g_current_preprocessing_state) {
+ mas_bring_client_to_foreground(current_maclient_appid);
+ g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
+ }
+ }
+ break;
+ case PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED:
+ {
+ if (MA_PREPROCESSING_ALLOW_FOLLOW_UP == mode ||
+ MA_PREPROCESSING_ALLOW_ALL == mode) {
+ g_current_preprocessing_state = PREPROCESSING_STATE_PREPROCESSING_FOLLOW_UP;
+ }
+ }
+ break;
+ case PREPROCESSING_STATE_EVENT_PREPROCESSING_SUCCEEDED:
+ {
+ g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
+ }
+ break;
+ case PREPROCESSING_STATE_EVENT_PREPROCESSING_FAILED:
+ {
+ mas_bring_client_to_foreground(current_maclient_appid);
+ g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
+ }
+ break;
+ }
+ return 0;
+}
+
bool service_app_create(void *data)
{
// Todo: add your code here.
}
#endif /* -TEST_CODE */
-Eina_Bool __launch_assistant_by_wakeup_appid_timer(char* appid)
+Eina_Bool process_wakeup_event_by_appid_timer(char* appid)
{
MAS_LOGD("[ENTER] appid(%s)", appid);
if (ui_panel_enabled) masc_ui_dbus_change_assistant(appid);
if ((pid = mas_get_client_pid_by_appid(appid)) != -1) {
mas_client_send_preprocessing_information(pid);
- masc_dbus_active_state_change(pid, MA_ACTIVE_STATE_ACTIVE);
- /* Bring MA client to foreground - is there a better way instead of launching? */
- mas_launch_client_by_appid(appid, CLIENT_LAUNCH_MODE_ACTIVATION);
+ mas_client_activate(pid);
} else {
// Appropriate MA Client not available, trying to launch new one
MAS_LOGD("MA Client with appid %s does not exist, launching client", appid);
mas_launch_client_by_appid(appid, CLIENT_LAUNCH_MODE_ACTIVATION);
}
+ mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_WAKEUP);
if (appid) free(appid);
return ECORE_CALLBACK_CANCEL;
}
-Eina_Bool __launch_assistant_by_wakeup_word_timer(char* wakeup_word)
+Eina_Bool process_wakeup_event_by_word_timer(char* wakeup_word)
{
MAS_LOGD("[ENTER]");
if (!wakeup_word) return EINA_FALSE;
const char* appid = mas_get_client_appid_by_wakeup_word(wakeup_word);
- __launch_assistant_by_wakeup_appid_timer(strdup(appid));
+ process_wakeup_event_by_appid_timer(strdup(appid));
if (wakeup_word) free(wakeup_word);
#endif /* - TEST_CODE */
if (wakeup_info.wakeup_appid) {
ecore_thread_main_loop_begin();
- ecore_timer_add(0.0f, __launch_assistant_by_wakeup_appid_timer, (void*)strdup(wakeup_info.wakeup_appid));
+ ecore_timer_add(0.0f, process_wakeup_event_by_appid_timer, (void*)strdup(wakeup_info.wakeup_appid));
ecore_thread_main_loop_end();
} else if (wakeup_info.wakeup_word) {
ecore_thread_main_loop_begin();
- ecore_timer_add(0.0f, __launch_assistant_by_wakeup_word_timer, (void*)strdup(wakeup_info.wakeup_word));
+ ecore_timer_add(0.0f, process_wakeup_event_by_word_timer, (void*)strdup(wakeup_info.wakeup_word));
ecore_thread_main_loop_end();
}