Add APIs of setting multi-assistant mode. 50/202250/11
authorXie Ligang <ligang0.xie@samsung.com>
Tue, 26 Mar 2019 09:02:58 +0000 (17:02 +0800)
committerXie Ligang <ligang0.xie@samsung.com>
Wed, 3 Apr 2019 03:15:53 +0000 (11:15 +0800)
Change-Id: Ia22f0be6e44007d4e5f0705e942a21456d45267f
Signed-off-by: Xie Ligang <ligang0.xie@samsung.com>
client/CMakeLists.txt
common/multi_assistant_settings.c [new file with mode: 0644]
include/CMakeLists.txt
include/multi_assistant_settings.h [new file with mode: 0644]
packaging/multi-assistant.spec

index 648c0231a06659e7a4d998c6f408952eca01cb8d..87fb2cb095a001216112de6a9fa631a8f6fc45e1 100644 (file)
@@ -3,6 +3,7 @@ SET(SRCS
        ma_client.c
        ma_dbus.c
        ../common/ma_config_mgr.c
+       ../common/multi_assistant_settings.c
 )
 
 SET(UI_SRCS
@@ -10,6 +11,7 @@ SET(UI_SRCS
        ma_ui_client.c
        ma_ui_dbus.c
        ../common/ma_config_mgr.c
+       ../common/multi_assistant_settings.c
 )
 
 FOREACH(flag ${pkgs_CFLAGS})
diff --git a/common/multi_assistant_settings.c b/common/multi_assistant_settings.c
new file mode 100644 (file)
index 0000000..e0a027e
--- /dev/null
@@ -0,0 +1,115 @@
+#include "multi_assistant_settings.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "ma-assistant-setting"
+
+#define APPID_URL "db/multi-assistant/enabled_status/%s"
+
+#define ENABLED_ASSISTANT_URL "db/multi-assistant/enabled_assistants"
+
+#define DEFAULT_ASSISTANT_URL "db/multi-assistant/default_assistant_appid"
+
+#define MODE_URL "db/multi-assistant/multiple_mode"
+
+#define MAX_LEN 100
+
+bool ma_settings_get_multiple_mode() {
+    int res;
+    vconf_get_bool(MODE_URL, &res);
+    return res;
+}
+
+int ma_settings_set_multiple_mode(bool multiple) {
+    if (!ma_settings_get_multiple_mode()) {
+
+        if (vconf_set_bool(MODE_URL, multiple)) {
+            return MA_ERROR_NONE;
+        } else {
+            return MA_ERROR_OPERATION_FAILED;
+        }
+
+    } else {
+        return MA_ERROR_OPERATION_FAILED;
+    }
+}
+
+int ma_settings_change_voice_assistant(const char* app_id) {
+    int res = MA_ERROR_NONE;
+    char* previous_assistant = vconf_get_str(ENABLED_ASSISTANT_URL);
+    if (!ma_settings_get_multiple_mode() &&
+        previous_assistant &&
+        app_id) {
+
+        if(strncmp(app_id, previous_assistant, MAX_LEN) != 0) {
+            char new_assistant_url[MAX_LEN] = "", previous_assistant_url[MAX_LEN] = "";
+            snprintf(new_assistant_url, MAX_LEN, APPID_URL, app_id);
+            snprintf(previous_assistant_url, MAX_LEN, APPID_URL, previous_assistant);
+
+            if (vconf_set_bool(new_assistant_url, true) &&
+                vconf_set_bool(previous_assistant_url, false) &&
+                vconf_set_str(ENABLED_ASSISTANT_URL, app_id)) {
+                res = MA_ERROR_NONE;
+            } else {
+                res = MA_ERROR_OPERATION_FAILED;
+            }
+
+        } else {
+            res = MA_ERROR_NOT_SUPPORTED;
+        }
+
+    } else {
+        res = MA_ERROR_OPERATION_FAILED;
+    }
+
+    if (previous_assistant) {
+        free(previous_assistant);
+    }
+    return res;
+}
+
+int ma_settings_set_voice_assistant_enabled(const char* app_id, bool enabled) {
+    if (ma_settings_get_multiple_mode() && app_id != NULL) {
+        char assistant_url[MAX_LEN] = "";
+        snprintf(assistant_url, MAX_LEN, APPID_URL, app_id);
+
+        if (vconf_set_bool(assistant_url, enabled)) {
+            return MA_ERROR_NONE;
+        } else {
+            return MA_ERROR_OPERATION_FAILED;
+        }
+
+    } else {
+        return MA_ERROR_ENGINE_NOT_FOUND;
+    }
+}
+
+int ma_settings_set_default_voice_assistant(const char* app_id) {
+    int res = MA_ERROR_NONE;
+    char* previous_assistant = vconf_get_str(DEFAULT_ASSISTANT_URL);
+    if (ma_settings_get_multiple_mode() &&
+        previous_assistant &&
+        app_id) {
+
+       if(strncmp(app_id, previous_assistant, MAX_LEN) != 0) {
+
+            if (vconf_set_str(DEFAULT_ASSISTANT_URL, app_id)) {
+                res = MA_ERROR_NONE;
+            } else {
+                res = MA_ERROR_OPERATION_FAILED;
+            }
+
+        } else {
+            res = MA_ERROR_NOT_SUPPORTED;
+        }
+
+    } else {
+        res = MA_ERROR_OPERATION_FAILED;
+    }
+
+    if (previous_assistant) {
+        free(previous_assistant);
+    }
+    return res;
+}
\ No newline at end of file
index 43d40c32dc8e2064b5db8d5ec7d04f558dab94ac..7d2d2099a26e40bcffaea11b239d3d0d2548d9fe 100644 (file)
@@ -10,3 +10,4 @@ INSTALL(FILES ${CMAKE_BINARY_DIR}/include/multi-assistant-ui.pc DESTINATION ${LI
 INSTALL(FILES ${CMAKE_BINARY_DIR}/include/multi_assistant.h DESTINATION ${INCLUDEDIR})
 INSTALL(FILES ${CMAKE_BINARY_DIR}/include/multi_assistant_ui.h DESTINATION ${INCLUDEDIR})
 INSTALL(FILES ${CMAKE_BINARY_DIR}/include/multi_assistant_common.h DESTINATION ${INCLUDEDIR})
+INSTALL(FILES ${CMAKE_BINARY_DIR}/include/multi_assistant_settings.h DESTINATION ${INCLUDEDIR})
diff --git a/include/multi_assistant_settings.h b/include/multi_assistant_settings.h
new file mode 100644 (file)
index 0000000..37d16e0
--- /dev/null
@@ -0,0 +1,106 @@
+/**
+ * Copyright (c) 2011-2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __TIZEN_UIFW_MULTI_ASSISTANT_SETTINGS_H__
+#define __TIZEN_UIFW_MULTI_ASSISTANT_SETTINGS_H__
+
+#include <tizen.h>
+#include <dlog.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <vconf/vconf.h>
+#include <multi_assistant_common.h>
+
+/**
+ * @addtogroup CAPI_UIX_MULTI_ASSISTANT_MODULE
+ * @{
+ */
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * @brief Set multi-assistant multiple mode.
+ * @since_tizen 5.5
+ * @privlevel public
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #MA_ERROR_NONE Successful
+ * @retval #MA_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @param[in] multiple The state of multi-assistant need to be changed into
+ */
+int ma_settings_set_multiple_mode(bool multiple);
+
+/**
+ * @brief Change system's voice assistant.
+ * @since_tizen 5.5
+ * @remarks Valid only in single voice assistant mode.
+ * @privlevel public
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #MA_ERROR_NONE Successful
+ * @retval #MA_ERROR_NOT_SUPPORTED Not supported
+ * @retval #MA_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @param[in] app_id The app id of the voice assistant that need to be activated
+ */
+int ma_settings_change_voice_assistant(const char* app_id);
+
+/**
+ * @brief En/Disable a specific voice assistant.
+ * @since_tizen 5.5
+ * @remarks Valid only in multiple voice assistant mode.
+ * @privlevel public
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #MA_ERROR_NONE Successful
+ * @retval #MA_ERROR_NOT_SUPPORTED Not supported
+ * @retval #MA_ERROR_ENGINE_NOT_FOUND Engine not found
+ *
+ * @param[in] app_id The app id of the voice assistant that need to be changed
+ * @param[in] enabled The voice assistant need to be enabled or not
+ */
+int ma_settings_set_voice_assistant_enabled(const char* app_id, bool enabled);
+
+/**
+ * @brief Change system's default voice assistant.
+ * @since_tizen 5.5
+ * @remarks Valid only in multiple voice assistant mode.
+ * @privlevel public
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #MA_ERROR_NONE Successful
+ * @retval #MA_ERROR_NOT_SUPPORTED Not supported
+ * @retval #MA_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @param[in] app_id The app id of the voice assistant that need to set as default one
+ */
+int ma_settings_set_default_voice_assistant(const char* app_id);
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ * @}
+ */
+
+#endif /* __TIZEN_UIFW_MULTI_ASSISTANT_SETTINGS_H__ */
\ No newline at end of file
index 70e4a89502e3f240b2aa0b41d8a8450ac6476ddc..dcc5604adb64233a827905f504928dc313750a4e 100644 (file)
@@ -102,11 +102,13 @@ mkdir -p %{_libdir}/multiassistant/ma
 %{_includedir}/multi_assistant.h
 %{_includedir}/multi_assistant_ui.h
 %{_includedir}/multi_assistant_common.h
+%{_includedir}/multi_assistant_settings.h
 
 %files ui-devel
 %defattr(-,root,root,-)
 %{_libdir}/pkgconfig/multi-assistant-ui.pc
 %{_includedir}/multi_assistant_ui.h
 %{_includedir}/multi_assistant_common.h
+%{_includedir}/multi_assistant_settings.h