From: Ji-hoon Lee Date: Mon, 16 Sep 2019 05:50:51 +0000 (+0900) Subject: Add API : ma_set_preprocessing_allow_mode X-Git-Tag: submit/tizen/20190920.111209~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F23%2F214023%2F2;p=platform%2Fcore%2Fuifw%2Fmulti-assistant.git Add API : ma_set_preprocessing_allow_mode Change-Id: Ia7b4bf5c077d10d13677952d759a0ac85bf1de32 --- diff --git a/client/ma.c b/client/ma.c index 1df7170..c78c1d9 100644 --- a/client/ma.c +++ b/client/ma.c @@ -1520,3 +1520,41 @@ int ma_set_background_volume(double ratio) } return ret; } + +int ma_set_preprocessing_allow_mode(ma_preprocessing_allow_mode_e mode, const char* app_id) +{ + SLOG(LOG_DEBUG, TAG_MAC, "[Manager] Set preprocessing allow mode"); + + if (0 != __ma_get_feature_enabled()) { + SLOG(LOG_DEBUG, TAG_MAC, "@@@ [Manager] not supported"); + return MA_ERROR_NOT_SUPPORTED; + } + + if (0 != __ma_check_privilege()) { + return MA_ERROR_PERMISSION_DENIED; + } + + ma_state_e state; + if (0 != ma_client_get_client_state(g_ma, &state)) { + SLOG(LOG_ERROR, TAG_MAC, "[ERROR] A handle is not available"); + SLOG(LOG_DEBUG, TAG_MAC, "@@@"); + return MA_ERROR_INVALID_STATE; + } + + /* check state */ + if (state != MA_STATE_READY) { + SLOG(LOG_ERROR, TAG_MAC, "[ERROR] Invalid State: Current state is not 'READY', state(%d)", state); + SLOG(LOG_DEBUG, TAG_MAC, "@@@"); + return MA_ERROR_INVALID_STATE; + } + + /* change system volume */ + int pid = getpid(); + int ret = ma_dbus_set_preprocessing_allow_mode(pid, mode, app_id); + if (0 != ret) { + SLOG(LOG_WARN, TAG_MAC, "[WARNING] retry to change volume"); + } else { + SLOG(LOG_DEBUG, TAG_MAC, "[DEBUG] Success to send"); + } + return ret; +} diff --git a/client/ma_dbus.c b/client/ma_dbus.c index 67ea1bf..b7bf094 100644 --- a/client/ma_dbus.c +++ b/client/ma_dbus.c @@ -1161,3 +1161,69 @@ int ma_dbus_set_background_volume(int pid, double ratio) return 0; } + +int ma_dbus_set_preprocessing_allow_mode(int pid, ma_preprocessing_allow_mode_e mode, const char *app_id) +{ + if (0 != __dbus_check()) { + return MA_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + msg = dbus_message_new_method_call( + MA_SERVER_SERVICE_NAME, + MA_SERVER_SERVICE_OBJECT_PATH, + MA_SERVER_SERVICE_INTERFACE, + MA_METHOD_SET_PREPROCESSING_ALLOW_MODE); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_MAC, "@@ Request multi-assistant change system volume : Fail to make message"); //LCOV_EXCL_LINE + return MA_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_MAC, "[DEBUG] multi-assistant change system volume"); + } + + char* tmp_app_id = NULL; + if (NULL != app_id) { + tmp_app_id = strdup(app_id); + } else { + tmp_app_id = strdup("#NULL"); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &mode, + DBUS_TYPE_STRING, &tmp_app_id, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + DBusError error; + dbus_error_init (&error); + if (!dbus_connection_send(g_conn_sender, msg, NULL)) { + + if (dbus_error_is_set (&error)) { + SLOG(LOG_ERROR, TAG_MAC, "[Dbus ERROR] Fail to Send : %s", error.message); //LCOV_EXCL_LINE + dbus_error_free (&error); + } else { + SLOG(LOG_ERROR, TAG_MAC, "[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE + } + if (NULL != tmp_app_id) { + free(tmp_app_id); + tmp_app_id = NULL; + } + return MA_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_MAC, "[Dbus DEBUG] Success to Send"); + dbus_connection_flush(g_conn_sender); + } + + dbus_message_unref(msg); + + if (NULL != tmp_app_id) { + free(tmp_app_id); + tmp_app_id = NULL; + } + + return 0; +} diff --git a/client/ma_dbus.h b/client/ma_dbus.h index 56ce898..2dc4cf8 100644 --- a/client/ma_dbus.h +++ b/client/ma_dbus.h @@ -57,6 +57,8 @@ int ma_dbus_get_recording_audio_source_type(int pid, char** type); int ma_dbus_set_background_volume(int pid, double ratio); +int ma_dbus_set_preprocessing_allow_mode(int pid, ma_preprocessing_allow_mode_e mode, const char *app_id); + #ifdef __cplusplus } #endif diff --git a/common/ma_defs.h b/common/ma_defs.h index bcbf510..6e24b84 100644 --- a/common/ma_defs.h +++ b/common/ma_defs.h @@ -77,6 +77,7 @@ extern "C" #define MA_METHOD_UPDATE_VOICE_FEEDBACK_STATE "ma_method_update_voice_feedback_state" #define MA_METHOD_SEND_ASSISTANT_SPECIFIC_COMMAND "ma_method_send_assistant_specific_command" #define MA_METHOD_SET_BACKGROUND_VOLUME "ma_method_set_background_volume" +#define MA_METHOD_SET_PREPROCESSING_ALLOW_MODE "ma_method_set_preprocessing_allow_mode" #define MA_METHOD_ERROR "ma_method_error" #define MA_UI_METHOD_INITIALIZE "ma_ui_method_initialize" diff --git a/include/multi_assistant.h b/include/multi_assistant.h index 1b90d12..fdc3748 100644 --- a/include/multi_assistant.h +++ b/include/multi_assistant.h @@ -583,6 +583,27 @@ int ma_get_recording_audio_source_type(char** type); */ int ma_set_background_volume(double ratio); +/** + * @brief Sets the preprocessing allow mode. + * @since_tizen 5.5 + * @privlevel public + * @privilege %http://tizen.org/privilege/recorder + * + * @remarks If the @a app_id is NULL, allow mode will be applied regardless of app_id. + * @param[in] mode The preprocessing allow mode to be set + * @param[in] app_id The application ID of the assistant to perform preprocessing + * + * @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_PERMISSION_DENIED Permission denied + * @retval #MA_ERROR_INVALID_STATE Invalid state + * @retval #MA_ERROR_OPERATION_FAILED Operation failed + * + * @pre The state should be #MA_STATE_READY. + */ +int ma_set_preprocessing_allow_mode(ma_preprocessing_allow_mode_e mode, const char* app_id); + #ifdef __cplusplus } #endif diff --git a/include/multi_assistant_common.h b/include/multi_assistant_common.h index f19bfc8..c14b526 100644 --- a/include/multi_assistant_common.h +++ b/include/multi_assistant_common.h @@ -140,6 +140,17 @@ typedef enum { MA_ACTIVE_STATE_ACTIVE = 1, /**< 'Active' state */ } ma_active_state_e; +/** + * @brief Enumerations for allowing preprocessing by other voice assistants. + * @since_tizen 5.5 + */ +typedef enum { + MA_PREPROCESSING_ALLOW_NONE = 0, /**< No preprocessing allowed */ + MA_PREPROCESSING_ALLOW_UTTERANCE, /**< Preprocessing allowed for utterance audio only */ + MA_PREPROCESSING_ALLOW_FOLLOW_UP, /**< Preprocessing allowed for follow-up audio only */ + MA_PREPROCESSING_ALLOW_ALL, /**< Preprocessing allowed for all audio */ +} ma_preprocessing_allow_mode_e; + /** * @brief Called when the client state is changed. * @since_tizen 5.0