Support background/foreground preprocessing selectively 62/216562/2
authorJi-hoon Lee <dalton.lee@samsung.com>
Tue, 29 Oct 2019 02:11:34 +0000 (11:11 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Tue, 29 Oct 2019 02:20:29 +0000 (11:20 +0900)
Change-Id: If8d8d875f35a08ec8463fe0549b0c9f35df0e2a8

inc/multi_assistant_service.h
src/multi_assistant_service.c
src/multi_assistant_service_plugin.c

index 0a79b99..0bbc37a 100644 (file)
@@ -98,8 +98,7 @@ typedef enum {
 } PREPROCESSING_STATE;
 
 typedef enum {
-       PREPROCESSING_STATE_EVENT_WAKEUP,
-       PREPROCESSING_STATE_EVENT_ACTIVE_ASSISTANT_LAUNCHED,
+       PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED,
        PREPROCESSING_STATE_EVENT_PREPROCESSING_ALLOW_MODE_CHANGED,
        PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED,
        PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED,
index 278c60c..b2da67b 100644 (file)
@@ -248,7 +248,7 @@ int mas_client_initialize(int pid)
                        if (g_wakeup_maclient_appid && strncmp(g_wakeup_maclient_appid, appid, MAX_APPID_LEN) == 0) {
                                g_wakeup_maclient_appid = NULL;
                                mas_client_activate(pid);
-                               mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ACTIVE_ASSISTANT_LAUNCHED);
+                               mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED);
                        } else {
                                MAS_LOGE("[ERROR] g_wakeup_maclient_appid and appid differ : %s %s",
                                        (g_wakeup_maclient_appid ? g_wakeup_maclient_appid : "NULL"), appid);
@@ -503,11 +503,9 @@ int mas_client_send_preprocessing_result(int pid, bool result)
 
        if (result) {
                MAS_LOGD("Preprocessing succeeded, bring (%s) to foreground", pid_appid);
-               mas_bring_client_to_foreground(pid_appid);
                mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_SUCCEEDED);
        } else {
                MAS_LOGD("Preprocessing failed, bring (%s) to foreground", current_maclient_appid);
-               mas_bring_client_to_foreground(current_maclient_appid);
                mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_FAILED);
        }
 
@@ -1105,6 +1103,9 @@ ma_preprocessing_allow_mode_e get_preprocessing_allow_mode(const char* appid)
        return MA_PREPROCESSING_ALLOW_NONE;
 }
 
+/* This might need to be read from settings in the future, but using macro for now */
+//#define BRING_PREPROCESSING_ASSISTANT_TO_FRONT
+
 int mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT event)
 {
        const char* current_maclient_appid = NULL;
@@ -1116,28 +1117,40 @@ int mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT event)
        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:
+               case PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED:
                {
-                       if (!check_preprocessing_assistant_exists()) {
-                               mas_bring_client_to_foreground(current_maclient_appid);
-                       }
+#ifndef BRING_PREPROCESSING_ASSISTANT_TO_FRONT
+                       /* If there is no need to bring preprocessing assistant to front,
+                               current_maclient should always be brought to front */
+                       mas_bring_client_to_foreground(current_maclient_appid);
+#endif
                        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;
+                       if (check_preprocessing_assistant_exists()) {
+                               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;
+                                       }
                                }
+                       } else {
+#ifdef BRING_PREPROCESSING_ASSISTANT_TO_FRONT
+                               /* If preprocessing assistant does not exist, there is no way to enable
+                                       preprocessing assistant, so bring current maclient to front right away */
+                               mas_bring_client_to_foreground(current_maclient_appid);
+#endif
                        }
                }
                break;
                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;
+                       /* Enable preprocessing mode only if the preprocessing assistant exists */
+                       if (check_preprocessing_assistant_exists()) {
+                               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;
+                                       }
                                }
                        }
                }
@@ -1147,27 +1160,53 @@ int mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT event)
                        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);
+                               /* If preprocessing assistant does not exist, the current_maclient
+                                       would have been brought to front already on wakeup event */
+#ifdef BRING_PREPROCESSING_ASSISTANT_TO_FRONT
+                               if (check_preprocessing_assistant_exists()) {
+                                       mas_bring_client_to_foreground(current_maclient_appid);
+                               }
+#endif
                                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;
+                       g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
+                       if (check_preprocessing_assistant_exists()) {
+                               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:
                {
+#ifdef BRING_PREPROCESSING_ASSISTANT_TO_FRONT
+                       if (PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED == g_current_preprocessing_state ||
+                               PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED == g_current_preprocessing_state) {
+                               char* vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
+                               MAS_LOGD("preprocessing_assistant_appid : %s", vconf_str);
+                               if (vconf_str) {
+                                       mas_bring_client_to_foreground(vconf_str);
+                                       free(vconf_str);
+                                       vconf_str = NULL;
+                               }
+                       }
+#endif
                        g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
                }
                break;
                case PREPROCESSING_STATE_EVENT_PREPROCESSING_FAILED:
                {
-                       mas_bring_client_to_foreground(current_maclient_appid);
+#ifdef BRING_PREPROCESSING_ASSISTANT_TO_FRONT
+                       if (PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED == g_current_preprocessing_state ||
+                               PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED == g_current_preprocessing_state) {
+                               mas_bring_client_to_foreground(current_maclient_appid);
+                       }
+#endif
                        g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
                }
                break;
index a04366f..5e9e063 100644 (file)
@@ -109,12 +109,12 @@ Eina_Bool process_wakeup_event_by_appid_timer(char* appid)
        if ((pid = mas_get_client_pid_by_appid(appid)) != -1) {
                mas_client_send_preprocessing_information(pid);
                mas_client_activate(pid);
+               mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED);
        } 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);