Add API : ma_set_preprocessing_allow_mode 23/214023/2
authorJi-hoon Lee <dalton.lee@samsung.com>
Mon, 16 Sep 2019 05:50:51 +0000 (14:50 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Wed, 18 Sep 2019 01:16:04 +0000 (10:16 +0900)
Change-Id: Ia7b4bf5c077d10d13677952d759a0ac85bf1de32

client/ma.c
client/ma_dbus.c
client/ma_dbus.h
common/ma_defs.h
include/multi_assistant.h
include/multi_assistant_common.h

index 1df7170007b3e35b877e7d3829da85e02b6c398b..c78c1d9781cc7fe2d20f5cd3d7868533e2de9ad6 100644 (file)
@@ -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;
+}
index 67ea1bfef965b838a46789150aff064ab1dbd5cd..b7bf0948a6ae5bf4f3e4dc79d7b0dccbeaa9513e 100644 (file)
@@ -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;
+}
index 56ce8981ab1e2bfb426c457537c497051d65ee5d..2dc4cf88eba1f8cee2955345537a4f5dbc71e8dd 100644 (file)
@@ -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
index bcbf510f18c578c94b8d439f53e0beccbc1ebc12..6e24b848e301212d1beb3edb423952ee124f6664 100644 (file)
@@ -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"
index 1b90d1215bae260f079587ffdf5de74cfe052bdf..fdc3748541a95771c95c2024c13337899324e39c 100644 (file)
@@ -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
index f19bfc844547fb86cad114456ac18b6550f581bf..c14b5262c9a1c8065820f72b090974f2eb06d85e 100644 (file)
@@ -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