Disable common UI when custom_ui'ed assistant gets woken up
authorJi-hoon Lee <dalton.lee@samsung.com>
Tue, 2 Apr 2019 09:07:34 +0000 (18:07 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Tue, 2 Apr 2019 09:08:00 +0000 (18:08 +0900)
Change-Id: I72a8381ff47f88f108fb6661f6e7cafa34d202be

inc/multi_assistant_config.h
inc/multi_assistant_main.h
inc/multi_assistant_service.h
src/multi_assistant_config.c
src/multi_assistant_dbus.c
src/multi_assistant_dbus.h
src/multi_assistant_service.c
src/multi_assistant_service_plugin.c

index 72e4a8b..454bc10 100644 (file)
@@ -18,6 +18,7 @@
 #ifndef __MULTI_ASSISTANT_CONFIG_H__
 #define __MULTI_ASSISTANT_CONFIG_H__
 
+#include <tizen.h>
 #include <tzplatform_config.h>
 
 #ifdef __cplusplus
@@ -58,9 +59,10 @@ typedef struct {
        const char* supported_lang[MAX_SUPPORTED_LANGUAGE_NUM];
        int cnt_lang;
        const char* wakeup_engine;
+       bool custom_ui_option;
 } ma_assistant_info_s;
 
-typedef int (*mas_config_assistant_info_cb)(const char* appid, const char* name, const char* icon_path, const char* wakeup_list[], int cnt_wakeup, const char* supported_lang[], int cnt_lang, const char* wakeup_engine, void* user_data);
+typedef int (*mas_config_assistant_info_cb)(const char* appid, const char* name, const char* icon_path, const char* wakeup_list[], int cnt_wakeup, const char* supported_lang[], int cnt_lang, const char* wakeup_engine, bool custom_ui_option, void* user_data);
 int mas_config_get_assistant_info(mas_config_assistant_info_cb callback, void* user_data);
 
 #ifdef __cplusplus
index fa0f751..a07013d 100644 (file)
@@ -78,5 +78,6 @@
 #define MAS_UI_METHOD_CHANGE_ASSISTANT                         "mas_ui_method_change_assistant"
 #define MAS_UI_METHOD_ERROR                                                    "mas_ui_method_error"
 #define MAS_UI_METHOD_SEND_RECOGNITION_RESULT          "mas_ui_method_send_recognition_result"
+#define MAS_UI_METHOD_ENABLE_COMMON_UI                         "mas_ui_method_enable_common_ui"
 
 #endif /* __MULTI_ASSISTANT_SERVICE_H__ */
index adeff4a..3ac83ad 100644 (file)
@@ -63,6 +63,8 @@ int mas_get_client_pid_by_wakeup_word(const char *wakeup_word);
 
 int mas_get_client_pid_by_appid(const char *appid);
 
+bool mas_get_client_custom_ui_option_by_appid(const char *appid);
+
 const char* mas_get_client_appid_by_wakeup_word(const char *wakeup_word);
 
 int mas_set_current_client_by_wakeup_word(const char *wakeup_word);
index 1c3f9ab..c15f73f 100644 (file)
@@ -81,6 +81,7 @@ int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, const
        memset(temp->supported_lang, 0x00, sizeof(temp->supported_lang));
        temp->cnt_lang = 0;
        temp->wakeup_engine = NULL;
+       temp->custom_ui_option = false;
 
        while (cur != NULL) {
                if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar *)MA_TAG_ASSISTANT_LANGUAGE_SET)) {
@@ -139,6 +140,15 @@ int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, const
                                MAS_LOGD("Wakeup Engine : %s", key);
                                xmlFree(key);
                        }
+               } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_CUSTOM_UI)) {
+                       key = xmlNodeGetContent(cur);
+                       if (key) {
+                               if (0 == xmlStrcasecmp(key, "true")) {
+                                       temp->custom_ui_option = true;
+                               }
+                               MAS_LOGD("Use custom UI : %d", temp->custom_ui_option);
+                               xmlFree(key);
+                       }
                }
 
                cur = cur->next;
@@ -147,7 +157,7 @@ int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, const
        if (callback) {
                callback(temp->app_id, temp->name, temp->icon_path,
                        temp->wakeup_list, temp->cnt_wakeup, temp->supported_lang,
-                       temp->cnt_lang, temp->wakeup_engine, user_data);
+                       temp->cnt_lang, temp->wakeup_engine, temp->custom_ui_option, user_data);
        }
 
        if (temp->app_id) {
index 75c57b1..a104acf 100644 (file)
@@ -595,6 +595,46 @@ int masc_ui_dbus_send_recognition_result(int pid, int result)
        return 0;
 }
 
+int masc_ui_dbus_enable_common_ui(int enable)
+{
+       if (0 != __dbus_check()) {
+               return -1; //MAS_ERROR_OPERATION_FAILED;
+       }
+
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+                         MA_UI_CLIENT_SERVICE_NAME,
+                         MA_UI_CLIENT_SERVICE_OBJECT_PATH,
+                         MA_UI_CLIENT_SERVICE_INTERFACE,
+                         MAS_UI_METHOD_ENABLE_COMMON_UI);
+
+       if (NULL == msg) {
+               MAS_LOGE("@@ Request multi-assistant enable common ui : Fail to make message");
+               return -1; //MA_ERROR_OPERATION_FAILED;
+       } else {
+               MAS_LOGD("[DEBUG] multi-assistant enable common ui (%d)", enable);
+       }
+
+       dbus_message_append_args(msg,
+               DBUS_TYPE_INT32, &enable,
+               DBUS_TYPE_INVALID);
+
+       dbus_message_set_no_reply(msg, TRUE);
+
+       if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
+               MAS_LOGE("[Dbus ERROR] Fail to Send");
+               return -1; // MAS_ERROR_OPERATION_FAILED;
+       } else {
+               MAS_LOGD("[Dbus DEBUG] Success to Send ASR result");
+               dbus_connection_flush(g_conn_sender);
+       }
+
+       dbus_message_unref(msg);
+
+       return 0;
+}
+
 static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
 {
        if (NULL == g_conn_listener)    return ECORE_CALLBACK_RENEW;
index 8cadc79..d28c716 100644 (file)
@@ -43,6 +43,9 @@ int masc_ui_dbus_change_assistant(char* app_id);
 
 int masc_ui_dbus_send_error_message(int reason, const char* err_msg);
 
+int masc_ui_dbus_send_recognition_result(int pid, int result);
+
+int masc_ui_dbus_enable_common_ui(int enable);
 
 #ifdef __cplusplus
 }
index 22c53cc..4dc0376 100644 (file)
@@ -41,10 +41,11 @@ static const char *g_current_lang = "en_US";
 #define MAX_WAKEUP_WORDS_NUM 4
 #define MAX_WAKEUP_WORD_LEN 255
 typedef struct {
-       Eina_Bool used;
+       bool used;
        char appid[MAX_APPID_LEN];
        char wakeup_word[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN];
        char wakeup_engine[MAX_APPID_LEN];
+       bool custom_ui_option;
 } ma_client_info;
 
 static ma_client_info g_maclient_info[MAX_MACLIENT_INFO_NUM];
@@ -376,6 +377,9 @@ int mas_ui_client_change_assistant(const char* appid)
                return -1;
        }
 
+       bool use_custom_ui = mas_get_client_custom_ui_option_by_appid(appid);
+       masc_ui_dbus_enable_common_ui(!use_custom_ui);
+
        mas_set_current_client_by_appid(appid);
        int pid = mas_get_client_pid_by_appid(appid);
        if (pid != -1) {
@@ -411,7 +415,7 @@ int mas_ui_client_change_assistant(const char* appid)
 int __mas_assistant_info_cb(const char* appid, const char* name,
                const char* icon_path, const char* wakeup_list[], int cnt_wakeup,
                const char* supported_lang[], int cnt_lang, const char* wakeup_engine,
-               void* user_data) {
+               bool custom_ui_option, void* user_data) {
        MAS_LOGD("__mas_assistant_info_cb called");
 
        if (NULL == appid) {
@@ -422,13 +426,13 @@ int __mas_assistant_info_cb(const char* appid, const char* name,
        int index = -1;
        int loop = 0;
        while(-1 == index && loop < MAX_MACLIENT_INFO_NUM) {
-               if (EINA_FALSE == g_maclient_info[loop].used) {
+               if (false == g_maclient_info[loop].used) {
                        index = loop;
                }
                loop++;
        }
        if (-1 != index) {
-               g_maclient_info[index].used = EINA_TRUE;
+               g_maclient_info[index].used = true;
                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';
@@ -451,6 +455,7 @@ int __mas_assistant_info_cb(const char* appid, const char* name,
                        g_maclient_info[index].wakeup_engine[0] = '\0';
                        MAS_LOGW("Wakeup engine information not provided for : %s", appid);
                }
+               g_maclient_info[index].custom_ui_option = custom_ui_option;
        } else {
                MAS_LOGD("Couldn't find an empty slot for storing assistant info");
        }
@@ -578,6 +583,21 @@ int mas_get_client_pid_by_appid(const char *appid)
        return ret;
 }
 
+bool mas_get_client_custom_ui_option_by_appid(const char *appid)
+{
+       bool ret = false;
+       for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
+               if (g_maclient_info[loop].used &&
+                       0 < strlen(g_maclient_info[loop].appid) &&
+                       0 < strlen(g_maclient_info[loop].wakeup_word[0])) {
+                       if (strncmp(appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
+                               ret = g_maclient_info[loop].custom_ui_option;
+                       }
+               }
+       }
+       return ret;
+}
+
 int mas_get_client_pid_by_wakeup_word(const char *wakeup_word)
 {
        const char *appid = mas_get_client_appid_by_wakeup_word(wakeup_word);
index 0b55e8f..0da824a 100644 (file)
@@ -89,6 +89,9 @@ Eina_Bool __launch_assistant_by_wakeup_appid_timer(char* appid)
        int pid = -1;
        if (!appid) return ECORE_CALLBACK_CANCEL;
 
+       bool use_custom_ui = mas_get_client_custom_ui_option_by_appid(appid);
+       masc_ui_dbus_enable_common_ui(!use_custom_ui);
+
        mas_set_current_client_by_appid(appid);
        masc_ui_dbus_change_assistant(appid);
        if ((pid = mas_get_client_pid_by_appid(appid)) != -1) {