From 160ddf2c716f3d1ee4d6a90403b4624ac36a19fb Mon Sep 17 00:00:00 2001 From: Xie Ligang Date: Tue, 26 Mar 2019 17:02:58 +0800 Subject: [PATCH] Add APIs of setting multi-assistant mode. Change-Id: Ia22f0be6e44007d4e5f0705e942a21456d45267f Signed-off-by: Xie Ligang --- client/CMakeLists.txt | 2 + common/multi_assistant_settings.c | 115 +++++++++++++++++++++++++++++ include/CMakeLists.txt | 1 + include/multi_assistant_settings.h | 106 ++++++++++++++++++++++++++ packaging/multi-assistant.spec | 2 + 5 files changed, 226 insertions(+) create mode 100644 common/multi_assistant_settings.c create mode 100644 include/multi_assistant_settings.h diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 648c023..87fb2cb 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -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 index 0000000..e0a027e --- /dev/null +++ b/common/multi_assistant_settings.c @@ -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 diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 43d40c3..7d2d209 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -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 index 0000000..37d16e0 --- /dev/null +++ b/include/multi_assistant_settings.h @@ -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 +#include +#include +#include +#include +#include + +/** + * @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 diff --git a/packaging/multi-assistant.spec b/packaging/multi-assistant.spec index 70e4a89..dcc5604 100644 --- a/packaging/multi-assistant.spec +++ b/packaging/multi-assistant.spec @@ -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 -- 2.34.1