Reduce duplicate code for getting client state 89/277689/2
authorInHong Han <inhong1.han@samsung.com>
Tue, 12 Jul 2022 07:00:47 +0000 (16:00 +0900)
committerInHong Han <inhong1.han@samsung.com>
Tue, 12 Jul 2022 07:18:42 +0000 (16:18 +0900)
Change-Id: I63187e2d3b343280657ca1ab7a3b7768c9a2eb84

client/ma.c
client/ma_ui.c

index d6f20387c9e4bcdad1f3d0830cf4e6133b8aff86..8647fd91a70d61bc668c863d70c99fdc7f6a1987 100644 (file)
@@ -218,16 +218,41 @@ static int __ma_check_volume_set_privilege()
        return MA_ERROR_NONE;
 }
 
-int ma_initialize(void)
+static int __ma_validate_client(bool recorder_privilege, bool client_state, ma_state_e *state)
 {
        if (0 != __ma_get_feature_enabled()) {
                return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
        }
 
-       if (0 != __ma_check_recorder_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
+       if (recorder_privilege) {
+               if (0 != __ma_check_recorder_privilege()) {
+                       return MA_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
+               }
+       }
+
+       if (client_state) {
+               if (false == ma_client_is_valid(g_ma)) {
+                       MA_SLOGE("[ERROR] NOT initialized"); //LCOV_EXCL_LINE
+                       return MA_ERROR_INVALID_STATE;
+               }
+
+               ma_state_e ma_state;
+               if (0 != ma_client_get_client_state(g_ma, &ma_state)) {
+                       MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
+                       return MA_ERROR_INVALID_STATE;
+               }
+               *state = ma_state;
        }
 
+       return MA_ERROR_NONE;
+}
+
+int ma_initialize(void)
+{
+       int ret = MA_ERROR_NONE;
+       ret = __ma_validate_client(true, false, NULL);
+       if (MA_ERROR_NONE != ret) return ret;
+
        MA_SLOGE("[Client DEBUG] Initialize"); //LCOV_EXCL_LINE
 
        /* check handle */
@@ -281,25 +306,12 @@ static void __ma_internal_unprepare(void)
 
 int ma_deinitialize(void)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       if (0 != __ma_check_recorder_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
-       }
-
        MA_SLOGE("[Client DEBUG] Deinitialize"); //LCOV_EXCL_LINE
 
-       if (false == ma_client_is_valid(g_ma)) {
-               MA_SLOGE("[ERROR] NOT initialized"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-       }
+       ret = __ma_validate_client(true, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        /* check state */
        switch (state) {
@@ -474,22 +486,12 @@ static void __end_prepare_func()
 
 int ma_prepare(void)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       if (0 != __ma_check_recorder_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
-       }
-
        MA_SLOGE("[Client DEBUG] Prepare"); //LCOV_EXCL_LINE
 
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
-
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       ret = __ma_validate_client(true, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -505,24 +507,16 @@ int ma_prepare(void)
 
 int ma_unprepare(void)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       if (0 != __ma_check_recorder_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
-       }
-
        MA_SLOGE("[Client DEBUG] Unprepare"); //LCOV_EXCL_LINE
 
-       MA_SLOGD("Deleting timer for retry_connection"); //LCOV_EXCL_LINE
-       ecore_main_loop_thread_safe_call_async(delete_retry_connection_timer, NULL);
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
-
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
+       ret = __ma_validate_client(true, true, &state);
+       if (MA_ERROR_INVALID_STATE == ret) {
+               MA_SLOGD("Deleting timer for retry_connection"); //LCOV_EXCL_LINE
+               ecore_main_loop_thread_safe_call_async(delete_retry_connection_timer, NULL);
+       } else if (MA_ERROR_NONE != ret) {
+               return ret;
        }
 
        /* check state */
@@ -1014,27 +1008,17 @@ int __ma_cb_voice_key_status_changed(int status)
 
 int ma_get_state(ma_state_e* state)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       if (0 != __ma_check_recorder_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Get current state"); //LCOV_EXCL_LINE
+       int ret = MA_ERROR_NONE;
+       ma_state_e tmp_state;
+       ret = __ma_validate_client(true, true, &tmp_state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (NULL == state) {
                MA_SLOGE("[Client ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-
-       ma_state_e tmp_state;
-       if (0 != ma_client_get_client_state(g_ma, &tmp_state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Get current state"); //LCOV_EXCL_LINE
 
        *state = tmp_state;
 
@@ -1043,23 +1027,18 @@ int ma_get_state(ma_state_e* state)
 
 int ma_get_current_language(char** language)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       if (0 != __ma_check_recorder_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
-       }
+       int ret = MA_ERROR_NONE;
+       ret = __ma_validate_client(true, false, NULL);
+       if (MA_ERROR_NONE != ret) return ret;
 
        MA_SLOGD("[Client DEBUG] Get current language"); //LCOV_EXCL_LINE
 
-
        if (NULL == language) {
                MA_SLOGE("[Client ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       int ret = -1;
+       ret = -1;
 /*     ret = ma_config_mgr_get_default_language(language);
        if (0 != ret) {
                MA_SLOGE("[Client ERROR] Fail to get current language"); //LCOV_EXCL_LINE
@@ -1075,25 +1054,16 @@ int ma_get_current_language(char** language)
 
 int ma_get_recording_audio_format(int *rate, ma_audio_channel_e *channel, ma_audio_type_e *audio_type)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       if (0 != __ma_check_recorder_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_validate_client(true, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (NULL == rate || NULL == channel || NULL == audio_type) {
                MA_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
-
        /* check state */
        if (state != MA_STATE_READY) {
                MA_SLOGE("[ERROR] Invalid State: Current state is not 'READY'"); //LCOV_EXCL_LINE
@@ -1103,8 +1073,8 @@ int ma_get_recording_audio_format(int *rate, ma_audio_channel_e *channel, ma_aud
        MA_SLOGI("[Client DEBUG] Get recording audio format"); //LCOV_EXCL_LINE
 
        int count = 0;
-       int ret = -1;
        int pid = getpid();
+       ret = -1;
        do {
                ret = ma_dbus_get_recording_audio_format(pid, rate, channel, audio_type);
                if (0 != ret) {
@@ -1130,24 +1100,17 @@ int ma_get_recording_audio_format(int *rate, ma_audio_channel_e *channel, ma_aud
 
 int ma_set_state_changed_cb(ma_state_changed_cb callback, void* user_data)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Set Multi-assistant client state changed cb"); //LCOV_EXCL_LINE
-
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (NULL == callback) {
                MA_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Set Multi-assistant client state changed cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -1162,18 +1125,12 @@ int ma_set_state_changed_cb(ma_state_changed_cb callback, void* user_data)
 
 int ma_unset_state_changed_cb(void)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Unset Multi-assistant client state changed cb"); //LCOV_EXCL_LINE
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Unset Multi-assistant client state changed cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -1188,24 +1145,17 @@ int ma_unset_state_changed_cb(void)
 
 int ma_set_error_cb(ma_error_cb callback, void* user_data)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Set Multi-assistant client error cb"); //LCOV_EXCL_LINE
-
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (NULL == callback) {
                MA_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Set Multi-assistant client error cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -1220,18 +1170,12 @@ int ma_set_error_cb(ma_error_cb callback, void* user_data)
 
 int ma_unset_error_cb(void)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Unset Multi-assistant client error cb"); //LCOV_EXCL_LINE
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Unset Multi-assistant client error cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -1246,24 +1190,17 @@ int ma_unset_error_cb(void)
 
 int ma_set_language_changed_cb(ma_language_changed_cb callback, void* user_data)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Set Multi-assistant language changed cb"); //LCOV_EXCL_LINE
-
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (NULL == callback) {
                MA_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Set Multi-assistant language changed cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -1278,18 +1215,12 @@ int ma_set_language_changed_cb(ma_language_changed_cb callback, void* user_data)
 
 int ma_unset_language_changed_cb(void)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Unset Multi-assistant language changed cb"); //LCOV_EXCL_LINE
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Unset Multi-assistant language changed cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -1304,23 +1235,17 @@ int ma_unset_language_changed_cb(void)
 
 int ma_set_audio_streaming_cb(ma_audio_streaming_cb callback, void* user_data)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Set Multi-assistant audio streaming cb"); //LCOV_EXCL_LINE
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (NULL == callback) {
                MA_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Set Multi-assistant audio streaming cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -1335,18 +1260,12 @@ int ma_set_audio_streaming_cb(ma_audio_streaming_cb callback, void* user_data)
 
 int ma_unset_audio_streaming_cb(void)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Unset Multi-assistant audio streaming cb"); //LCOV_EXCL_LINE
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Unset Multi-assistant audio streaming cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -1361,25 +1280,16 @@ int ma_unset_audio_streaming_cb(void)
 
 int ma_send_asr_result(ma_asr_result_event_e event, const char* asr_result)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       if (0 != __ma_check_recorder_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_validate_client(true, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (event < MA_ASR_RESULT_EVENT_PARTIAL_RESULT || event > MA_ASR_RESULT_EVENT_ERROR) {
                MA_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
-
        /* check state */
        if (state != MA_STATE_READY) {
                MA_SLOGE("[ERROR] Invalid State: Current state is not 'READY'"); //LCOV_EXCL_LINE
@@ -1396,7 +1306,7 @@ int ma_send_asr_result(ma_asr_result_event_e event, const char* asr_result)
                event, asr_result);
        //LCOV_EXCL_STOP
 
-       int ret = -1;
+       ret = -1;
        int pid = getpid();
        ret = ma_dbus_send_asr_result(pid, event, asr_result);
        if (0 != ret) {
@@ -1410,19 +1320,10 @@ int ma_send_asr_result(ma_asr_result_event_e event, const char* asr_result)
 
 int ma_send_result(const char* display_text, const char* utterance_text, const char* result_json)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       if (0 != __ma_check_recorder_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
-       }
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       ret = __ma_validate_client(true, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        /* check state */
        if (state != MA_STATE_READY) {
@@ -1439,7 +1340,7 @@ int ma_send_result(const char* display_text, const char* utterance_text, const c
                MA_SLOGD("[Client DEBUG] Input parameter is NULL."); //LCOV_EXCL_LINE
        }
 
-       int ret = -1;
+       ret = -1;
        int pid = getpid();
        ret = ma_dbus_send_result(pid, display_text, utterance_text, result_json);
        if (0 != ret) {
@@ -1453,19 +1354,10 @@ int ma_send_result(const char* display_text, const char* utterance_text, const c
 
 int ma_send_recognition_result(ma_recognition_result_event_e result)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       if (0 != __ma_check_recorder_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
-       }
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       ret = __ma_validate_client(true, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        /* check state */
        if (state != MA_STATE_READY) {
@@ -1475,7 +1367,7 @@ int ma_send_recognition_result(ma_recognition_result_event_e result)
 
        MA_SLOGE("[Client DEBUG] Send recognition result to the Multi-assistant : %d", result); //LCOV_EXCL_LINE
 
-       int ret = -1;
+       ret = -1;
        int pid = getpid();
        ret = ma_dbus_send_recognition_result(pid, result);
        if (0 != ret) {
@@ -1489,23 +1381,17 @@ int ma_send_recognition_result(ma_recognition_result_event_e result)
 
 int ma_set_active_state_changed_cb(ma_active_state_changed_cb callback, void* user_data)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Set Multi-assistant active state changed cb"); //LCOV_EXCL_LINE
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (NULL == callback) {
                MA_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Set Multi-assistant active state changed cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -1520,18 +1406,12 @@ int ma_set_active_state_changed_cb(ma_active_state_changed_cb callback, void* us
 
 int ma_unset_active_state_changed_cb(void)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Unset Multi-assistant active state changed cb"); //LCOV_EXCL_LINE
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Unset Multi-assistant active state changed cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -1546,19 +1426,10 @@ int ma_unset_active_state_changed_cb(void)
 
 int ma_start_receiving_audio_streaming_data(ma_audio_streaming_data_type_e type)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       if (0 != __ma_check_recorder_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
-       }
-
-       ma_state_e state;
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_validate_client(true, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        /* check state */
        if (state != MA_STATE_READY) {
@@ -1573,7 +1444,7 @@ int ma_start_receiving_audio_streaming_data(ma_audio_streaming_data_type_e type)
        ma_client_set_preprocessing_result_received(g_ma, false);
 #endif
 
-       int ret = -1;
+       ret = -1;
        int pid = getpid();
        ret = ma_dbus_start_streaming_audio_data(pid, type);
        if (0 != ret) {
@@ -1587,19 +1458,10 @@ int ma_start_receiving_audio_streaming_data(ma_audio_streaming_data_type_e type)
 
 int ma_stop_receiving_audio_streaming_data(ma_audio_streaming_data_type_e type)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       if (0 != __ma_check_recorder_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
-       }
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       ret = __ma_validate_client(true, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        /* check state */
        if (state != MA_STATE_READY) {
@@ -1609,7 +1471,7 @@ int ma_stop_receiving_audio_streaming_data(ma_audio_streaming_data_type_e type)
 
        MA_SLOGE("[Client DEBUG] Send streaming stop request to the Multi-assistant : %d", type); //LCOV_EXCL_LINE
 
-       int ret = -1;
+       ret = -1;
        int pid = getpid();
        ret = ma_dbus_stop_streaming_audio_data(pid, type);
        if (0 != ret) {
@@ -1623,19 +1485,10 @@ int ma_stop_receiving_audio_streaming_data(ma_audio_streaming_data_type_e type)
 
 int ma_update_voice_feedback_state(ma_voice_feedback_state_e feedback_state)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       if (0 != __ma_check_recorder_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
-       }
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       ret = __ma_validate_client(true, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        /* check state */
        if (state != MA_STATE_READY) {
@@ -1645,7 +1498,7 @@ int ma_update_voice_feedback_state(ma_voice_feedback_state_e feedback_state)
 
        MA_SLOGI("[Client DEBUG] Update voice feedback state to the Multi-assistant : %d", feedback_state); //LCOV_EXCL_LINE
 
-       int ret = -1;
+       ret = -1;
        int pid = getpid();
        ret = ma_dbus_update_voice_feedback_state(pid, feedback_state);
        if (0 != ret) {
@@ -1659,19 +1512,10 @@ int ma_update_voice_feedback_state(ma_voice_feedback_state_e feedback_state)
 
 int ma_send_assistant_specific_command(const char* command)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       if (0 != __ma_check_recorder_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
-       }
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       ret = __ma_validate_client(true, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        /* check state */
        if (state != MA_STATE_READY) {
@@ -1681,7 +1525,7 @@ int ma_send_assistant_specific_command(const char* command)
 
        MA_SLOGI("[Client DEBUG] Send assistant specific command to the Multi-assistant : %s", command); //LCOV_EXCL_LINE
 
-       int ret = -1;
+       ret = -1;
        int pid = getpid();
        ret = ma_dbus_send_assistant_specific_command(pid, command);
        if (0 != ret) {
@@ -1695,23 +1539,17 @@ int ma_send_assistant_specific_command(const char* command)
 
 int ma_set_wakeup_engine_command_cb(ma_wakeup_engine_command_cb callback, void* user_data)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Set Multi-assistant wakeup engine command cb"); //LCOV_EXCL_LINE
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (NULL == callback) {
                MA_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Set Multi-assistant wakeup engine command cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -1726,18 +1564,12 @@ int ma_set_wakeup_engine_command_cb(ma_wakeup_engine_command_cb callback, void*
 
 int ma_unset_wakeup_engine_command_cb(void)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Unset Multi-assistant wakeup engine command cb"); //LCOV_EXCL_LINE
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Unset Multi-assistant wakeup engine command cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -1845,21 +1677,16 @@ int ma_assistant_info_get_enabled_status(ma_assistant_info_h handle, bool* statu
 }
 
 int ma_get_recording_audio_source_type(char** type) {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (NULL == type) {
                MA_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
-
        /* check state */
        if (state != MA_STATE_READY) {
                MA_SLOGE("[ERROR] Invalid State: Current state is not 'READY'"); //LCOV_EXCL_LINE
@@ -1869,7 +1696,7 @@ int ma_get_recording_audio_source_type(char** type) {
        MA_SLOGI("[Client DEBUG] Get recording audio source type"); //LCOV_EXCL_LINE
 
        int count = 0;
-       int ret = -1;
+       ret = -1;
        int pid = getpid();
        do {
                ret = ma_dbus_get_recording_audio_source_type(pid, type);
@@ -1938,21 +1765,10 @@ int ma_set_preprocessing_allow_mode(ma_preprocessing_allow_mode_e mode, const ch
 {
        MA_SLOGD("[Manager] Set preprocessing allow mode"); //LCOV_EXCL_LINE
 
-       if (0 != __ma_get_feature_enabled()) {
-               MA_SLOGD("@@@ [Manager] not supported"); //LCOV_EXCL_LINE
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       if (0 != __ma_check_recorder_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
-       }
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               MA_SLOGD("@@@"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       ret = __ma_validate_client(true, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        /* check state */
        if (state != MA_STATE_READY) {
@@ -1968,7 +1784,7 @@ int ma_set_preprocessing_allow_mode(ma_preprocessing_allow_mode_e mode, const ch
 
        /* change system volume */
        int pid = getpid();
-       int ret = ma_dbus_set_preprocessing_allow_mode(pid, mode, app_id);
+       ret = ma_dbus_set_preprocessing_allow_mode(pid, mode, app_id);
        if (0 != ret) {
                MA_SLOGW("[WARNING] retry to set preprocessing allow mode"); //LCOV_EXCL_LINE
        } else {
@@ -1979,23 +1795,17 @@ int ma_set_preprocessing_allow_mode(ma_preprocessing_allow_mode_e mode, const ch
 
 int ma_set_preprocessing_information_changed_cb(ma_preprocessing_information_changed_cb callback, void* user_data)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Set Multi-assistant preprocessing information changed cb"); //LCOV_EXCL_LINE
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (NULL == callback) {
                MA_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Set Multi-assistant preprocessing information changed cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -2010,18 +1820,12 @@ int ma_set_preprocessing_information_changed_cb(ma_preprocessing_information_cha
 
 int ma_unset_preprocessing_information_changed_cb(void)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Unset Multi-assistant preprocessing information changed cb"); //LCOV_EXCL_LINE
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Unset Multi-assistant preprocessing information changed cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -2038,21 +1842,10 @@ int ma_send_preprocessing_result(bool is_success)
 {
        MA_SLOGD("[Manager] Send preprocessing result"); //LCOV_EXCL_LINE
 
-       if (0 != __ma_get_feature_enabled()) {
-               MA_SLOGD("@@@ [Manager] not supported"); //LCOV_EXCL_LINE
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       if (0 != __ma_check_recorder_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
-       }
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               MA_SLOGD("@@@"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       ret = __ma_validate_client(true, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (state != MA_STATE_READY) {
                MA_SLOGE("[ERROR] Invalid State: Current state is not 'READY', state(%d)", state); //LCOV_EXCL_LINE
@@ -2064,7 +1857,7 @@ int ma_send_preprocessing_result(bool is_success)
 
        /* Send preprocessing result */
        int pid = getpid();
-       int ret = ma_dbus_send_preprocessing_result(pid, is_success);
+       ret = ma_dbus_send_preprocessing_result(pid, is_success);
        if (0 != ret) {
                MA_SLOGW("[WARNING] retry to send preprocessing result"); //LCOV_EXCL_LINE
        } else {
@@ -2077,17 +1870,10 @@ int ma_set_wake_word_audio_require_flag(bool require)
 {
        MA_SLOGD("[Manager] Set wake word audio require flag"); //LCOV_EXCL_LINE
 
-       if (0 != __ma_get_feature_enabled()) {
-               MA_SLOGD("@@@ [Manager] not supported"); //LCOV_EXCL_LINE
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               MA_SLOGD("@@@"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (state != MA_STATE_READY) {
                MA_SLOGE("[ERROR] Invalid State: Current state is not 'READY', state(%d)", state); //LCOV_EXCL_LINE
@@ -2099,7 +1885,7 @@ int ma_set_wake_word_audio_require_flag(bool require)
 
        /* Set wake word audio require flag */
        int pid = getpid();
-       int ret = ma_dbus_set_wake_word_audio_require_flag(pid, require);
+       ret = ma_dbus_set_wake_word_audio_require_flag(pid, require);
        if (0 != ret) {
                MA_SLOGW("[WARNING] retry to set wake word audio require flag"); //LCOV_EXCL_LINE
        } else {
@@ -2110,23 +1896,17 @@ int ma_set_wake_word_audio_require_flag(bool require)
 
 int ma_set_audio_streaming_data_section_changed_cb(ma_audio_streaming_data_section_changed_cb callback, void* user_data)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Set Multi-assistant audio streaming data section changed cb"); //LCOV_EXCL_LINE
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (NULL == callback) {
                MA_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Set Multi-assistant audio streaming data section changed cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -2141,18 +1921,12 @@ int ma_set_audio_streaming_data_section_changed_cb(ma_audio_streaming_data_secti
 
 int ma_unset_audio_streaming_data_section_changed_cb(void)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Unset Multi-assistant audio streaming data section changed cb"); //LCOV_EXCL_LINE
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Unset Multi-assistant audio streaming data section changed cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -2168,23 +1942,17 @@ int ma_unset_audio_streaming_data_section_changed_cb(void)
 //LCOV_EXCL_START
 int ma_set_preprocessing_result_received_cb(ma_preprocessing_result_received_cb callback, void* user_data)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Set Multi-assistant preprocessing result received cb"); //LCOV_EXCL_LINE
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (NULL == callback) {
                MA_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Set Multi-assistant preprocessing result received cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -2199,18 +1967,12 @@ int ma_set_preprocessing_result_received_cb(ma_preprocessing_result_received_cb
 
 int ma_unset_preprocessing_result_received_cb(void)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Unset Multi-assistant preprocessing result received cb"); //LCOV_EXCL_LINE
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Unset Multi-assistant preprocessing result received cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -2234,23 +1996,16 @@ int ma_set_assistant_wakeup_language(const char* language)
 {
        MA_SLOGD("[Manager] Set assistant wakeup language"); //LCOV_EXCL_LINE
 
-       if (0 != __ma_get_feature_enabled()) {
-               MA_SLOGD("@@@ [Manager] not supported"); //LCOV_EXCL_LINE
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (NULL == language) {
                MA_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               MA_SLOGD("@@@"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
-
        if (state != MA_STATE_READY) {
                MA_SLOGE("[ERROR] Invalid State: Current state is not 'READY', state(%d)", state); //LCOV_EXCL_LINE
                MA_SLOGD("@@@"); //LCOV_EXCL_LINE
@@ -2261,7 +2016,7 @@ int ma_set_assistant_wakeup_language(const char* language)
 
        /* Set assistant language */
        int pid = getpid();
-       int ret = ma_dbus_set_assistant_wakeup_language(pid, language);
+       ret = ma_dbus_set_assistant_wakeup_language(pid, language);
        if (0 != ret) {
                MA_SLOGW("[WARNING] Failed to set assistant wakeup language"); //LCOV_EXCL_LINE
        } else {
@@ -2272,23 +2027,17 @@ int ma_set_assistant_wakeup_language(const char* language)
 
 int ma_set_service_state_changed_cb(ma_service_state_changed_cb callback, void* user_data)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Set Multi-assistant service state changed cb"); //LCOV_EXCL_LINE
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (NULL == callback) {
                MA_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Set Multi-assistant service state changed cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -2303,18 +2052,12 @@ int ma_set_service_state_changed_cb(ma_service_state_changed_cb callback, void*
 
 int ma_unset_service_state_changed_cb(void)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Unset Multi-assistant service state changed cb"); //LCOV_EXCL_LINE
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Unset Multi-assistant service state changed cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -2329,23 +2072,17 @@ int ma_unset_service_state_changed_cb(void)
 
 int ma_set_voice_key_status_changed_cb(ma_voice_key_status_changed_cb callback, void* user_data)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Set Multi-assistant voice key status changed cb"); //LCOV_EXCL_LINE
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (NULL == callback) {
                MA_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Set Multi-assistant voice key status changed cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -2360,18 +2097,12 @@ int ma_set_voice_key_status_changed_cb(ma_voice_key_status_changed_cb callback,
 
 int ma_unset_voice_key_status_changed_cb(void)
 {
-       if (0 != __ma_get_feature_enabled()) {
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
-
-       MA_SLOGD("[Client DEBUG] Unset Multi-assistant voice key status changed cb"); //LCOV_EXCL_LINE
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MA_SLOGD("[Client DEBUG] Unset Multi-assistant voice key status changed cb"); //LCOV_EXCL_LINE
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -2387,23 +2118,16 @@ int ma_unset_voice_key_status_changed_cb(void)
 int ma_add_wake_word(const char* wake_word, const char *language) {
        MA_SLOGD("[Manager] Add wake word"); //LCOV_EXCL_LINE
 
-       if (0 != __ma_get_feature_enabled()) {
-               MA_SLOGD("@@@ [Manager] not supported"); //LCOV_EXCL_LINE
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (NULL == wake_word || NULL == language) {
                MA_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               MA_SLOGD("@@@"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
-
        if (state != MA_STATE_READY) {
                MA_SLOGE("[ERROR] Invalid State: Current state is not 'READY', state(%d)", state); //LCOV_EXCL_LINE
                MA_SLOGD("@@@"); //LCOV_EXCL_LINE
@@ -2414,7 +2138,7 @@ int ma_add_wake_word(const char* wake_word, const char *language) {
 
        /* Add wake word */
        int pid = getpid();
-       int ret = ma_dbus_add_wake_word(pid, wake_word, language);
+       ret = ma_dbus_add_wake_word(pid, wake_word, language);
        if (0 != ret) {
                MA_SLOGW("[WARNING] Failed to add wake word"); //LCOV_EXCL_LINE
        } else {
@@ -2426,23 +2150,16 @@ int ma_add_wake_word(const char* wake_word, const char *language) {
 int ma_remove_wake_word(const char* wake_word, const char *language) {
        MA_SLOGD("[Manager] Remove wake word"); //LCOV_EXCL_LINE
 
-       if (0 != __ma_get_feature_enabled()) {
-               MA_SLOGD("@@@ [Manager] not supported"); //LCOV_EXCL_LINE
-               return MA_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (NULL == wake_word || NULL == language) {
                MA_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-       if (0 != ma_client_get_client_state(g_ma, &state)) {
-               MA_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               MA_SLOGD("@@@"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
-
        if (state != MA_STATE_READY) {
                MA_SLOGE("[ERROR] Invalid State: Current state is not 'READY', state(%d)", state); //LCOV_EXCL_LINE
                MA_SLOGD("@@@"); //LCOV_EXCL_LINE
@@ -2453,7 +2170,7 @@ int ma_remove_wake_word(const char* wake_word, const char *language) {
 
        /* Remove wake word */
        int pid = getpid();
-       int ret = ma_dbus_remove_wake_word(pid, wake_word, language);
+       ret = ma_dbus_remove_wake_word(pid, wake_word, language);
        if (0 != ret) {
                MA_SLOGW("[WARNING] Failed to remove wake word"); //LCOV_EXCL_LINE
        } else {
index 4bb992d0c8ccbc78bdd9914459eae09297d3807a..216cd1cbab4443331b92b4350d0a958aba578da9 100644 (file)
@@ -152,21 +152,43 @@ static int __ma_ui_check_privilege()
        return MA_ERROR_NONE;
 }
 
-
-
-int ma_ui_initialize(void)
+static int __ma_ui_validate_client(bool privilege, bool client_state, ma_state_e *state)
 {
        if (0 != __ma_ui_get_feature_enabled()) {
                MAUI_SLOGD("[UI] not supported");
                return MA_ERROR_NOT_SUPPORTED;
        }
 
-       if (0 != __ma_ui_check_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED;
+       if (privilege) {
+               if (0 != __ma_ui_check_privilege()) {
+                       return MA_ERROR_PERMISSION_DENIED;
+               }
        }
 
-       MAUI_SLOGE("[UI] Initialize");
+       if (client_state) {
+               if (false == ma_ui_client_is_valid(g_ma_ui)) {
+                       MAUI_SLOGE("[ERROR] NOT initialized");
+                       return MA_ERROR_INVALID_STATE;
+               }
+
+               ma_state_e ma_ui_state;
+               if (0 != ma_ui_client_get_client_state(g_ma_ui, &ma_ui_state)) {
+                       MAUI_SLOGE("[UI ERROR] A handle is not available");
+                       return MA_ERROR_INVALID_STATE;
+               }
+               *state = ma_ui_state;
+       }
+
+       return MA_ERROR_NONE;
+}
+
+int ma_ui_initialize(void)
+{
+       int ret = MA_ERROR_NONE;
+       ret = __ma_ui_validate_client(true, false, NULL);
+       if (MA_ERROR_NONE != ret) return ret;
 
+       MAUI_SLOGE("[UI] Initialize");
 
        /* check handle */
        if (true == ma_ui_client_is_valid(g_ma_ui)) {
@@ -216,27 +238,13 @@ static void __ma_ui_internal_unprepare(void)
 
 int ma_ui_deinitialze(void)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
-
-       if (0 != __ma_ui_check_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED;
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_ui_validate_client(true, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        MAUI_SLOGE("@@@ [UI] Deinitialize");
 
-       if (false == ma_ui_client_is_valid(g_ma_ui)) {
-               MAUI_SLOGE("[ERROR] NOT initialized");
-               return MA_ERROR_INVALID_STATE;
-       }
-
-       ma_state_e state;
-       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
-               MAUI_SLOGE("[UI ERROR] A handle is not available");
-       }
-
        /* check state */
        switch (state) {
        case MA_STATE_READY:
@@ -359,23 +367,13 @@ static void __end_prepare_thread(void *data, Ecore_Thread *thread)
 
 int ma_ui_prepare(void)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
-
-       if (0 != __ma_ui_check_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED;
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_ui_validate_client(true, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        MAUI_SLOGD("[UI] Prepare");
 
-       ma_state_e state;
-       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
-               MAUI_SLOGE("[UI ERROR] A handle is not available");
-               return MA_ERROR_INVALID_STATE;
-       }
-
        /* check state */
        if (MA_STATE_INITIALIZED != state) {
                MAUI_SLOGE("[UI ERROR] Invalid state: Current state is not 'Initialized' (%d)", state);
@@ -389,23 +387,13 @@ int ma_ui_prepare(void)
 
 int ma_ui_unprepare(void)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
-
-       if (0 != __ma_ui_check_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED;
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_ui_validate_client(true, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        MAUI_SLOGD("[UI] Unprepare");
 
-       ma_state_e state;
-       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
-               MAUI_SLOGE("[UI ERROR] A handle is not available");
-               return MA_ERROR_INVALID_STATE;
-       }
-
        /* check state */
        if (MA_STATE_READY != state) {
                MAUI_SLOGE("[UI ERROR] Invalid state: Current state is not 'READY' (%d)", state);
@@ -677,14 +665,10 @@ int __ma_ui_cb_enable_common_ui(bool enable)
 
 int ma_ui_get_state(ma_state_e* state)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
-
-       if (0 != __ma_ui_check_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED;
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e tmp_state;
+       ret = __ma_ui_validate_client(true, true, &tmp_state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        MAUI_SLOGD("[UI DEBUG] Get current state");
 
@@ -693,13 +677,6 @@ int ma_ui_get_state(ma_state_e* state)
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-
-       ma_state_e tmp_state;
-       if (0 != ma_ui_client_get_client_state(g_ma_ui, &tmp_state)) {
-               MAUI_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
-
        *state = tmp_state;
 
        return MA_ERROR_NONE;
@@ -707,14 +684,9 @@ int ma_ui_get_state(ma_state_e* state)
 
 int ma_ui_foreach_assistant_info(ma_ui_assistant_info_cb callback, void* user_data)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
-
-       if (0 != __ma_ui_check_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED;
-       }
+       int ret = MA_ERROR_NONE;
+       ret = __ma_ui_validate_client(true, false, NULL);
+       if (MA_ERROR_NONE != ret) return ret;
 
        MAUI_SLOGD("[UI] Get foreach assistant info");
 
@@ -723,7 +695,7 @@ int ma_ui_foreach_assistant_info(ma_ui_assistant_info_cb callback, void* user_da
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       int ret = -1;
+       ret = -1;
        ret = ma_config_mgr_get_assistant_info(callback, user_data);
        if (0 != ret) {
                MAUI_SLOGE("[UI ERROR] Fail to get assistant info");
@@ -735,14 +707,10 @@ int ma_ui_foreach_assistant_info(ma_ui_assistant_info_cb callback, void* user_da
 
 int ma_ui_set_default_assistant(const char* app_id)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
-
-       if (0 != __ma_ui_check_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED;
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_ui_validate_client(true, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        MAUI_SLOGD("[UI] Set a default assistant");
 
@@ -751,19 +719,13 @@ int ma_ui_set_default_assistant(const char* app_id)
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
-               MAUI_SLOGE("[UI ERROR] A handle is not available");
-               return MA_ERROR_INVALID_STATE;
-       }
-
        /* check state */
        if (MA_STATE_INITIALIZED!= state) {
                MAUI_SLOGE("[UI ERROR] Invalid state: Current state is not 'Initialized' (%d)", state);
                return MA_ERROR_INVALID_STATE;
        }
 
-       int ret = -1;
+       ret = -1;
 /*     ret = ma_config_mgr_set_default_assistant(app_id);
        if (0 != ret) {
                MAUI_SLOGE("[UI ERROR] Fail to set default assistant")_;
@@ -775,14 +737,10 @@ int ma_ui_set_default_assistant(const char* app_id)
 
 int ma_ui_change_assistant(const char* app_id)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
-
-       if (0 != __ma_ui_check_privilege()) {
-               return MA_ERROR_PERMISSION_DENIED;
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_ui_validate_client(true, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        MAUI_SLOGD("[UI] Change a assistant");
 
@@ -791,19 +749,13 @@ int ma_ui_change_assistant(const char* app_id)
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
-               MAUI_SLOGE("[UI ERROR] A handle is not available");
-               return MA_ERROR_INVALID_STATE;
-       }
-
        /* check state */
        if (MA_STATE_READY != state) {
                MAUI_SLOGE("[UI ERROR] Invalid state: Current state is not 'Initialized' (%d)", state);
                return MA_ERROR_INVALID_STATE;
        }
 
-       int ret = -1;
+       ret = -1;
        ma_ui_dbus_request_change_assistant(app_id);
 /*     ret = ma_config_mgr_change_assistant(app_id);
        if (0 != ret) {
@@ -817,26 +769,18 @@ int ma_ui_change_assistant(const char* app_id)
 
 int ma_ui_set_state_changed_cb(ma_state_changed_cb callback, void* user_data)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_ui_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        MAUI_SLOGD("[Client DEBUG] Set Multi-assistant client state changed cb");
 
-
        if (NULL == callback) {
                MAUI_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-
-       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
-               MAUI_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
-
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
                MAUI_SLOGE("[ERROR] Invalid State: Current state is not 'Initialized'"); //LCOV_EXCL_LINE
@@ -850,19 +794,12 @@ int ma_ui_set_state_changed_cb(ma_state_changed_cb callback, void* user_data)
 
 int ma_ui_unset_state_changed_cb(void)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
-
-       MAUI_SLOGD("[UI DEBUG] Unset Multi-assistant client state changed cb");
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
+       ret = __ma_ui_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
-       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
-               MAUI_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MAUI_SLOGD("[UI DEBUG] Unset Multi-assistant client state changed cb");
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -877,26 +814,18 @@ int ma_ui_unset_state_changed_cb(void)
 
 int ma_ui_set_error_cb(ma_error_cb callback, void* user_data)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_ui_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        MAUI_SLOGD("[Client DEBUG] Set Multi-assistant UI client error cb");
 
-
        if (NULL == callback) {
                MAUI_SLOGE("[ERROR] Invalid parameter"); //LCOV_EXCL_LINE
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-
-       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
-               MAUI_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
-
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
                MAUI_SLOGE("[ERROR] Invalid State: Current state is not 'Initialized'"); //LCOV_EXCL_LINE
@@ -910,19 +839,12 @@ int ma_ui_set_error_cb(ma_error_cb callback, void* user_data)
 
 int ma_ui_unset_error_cb(void)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
-
-       MAUI_SLOGD("[UI DEBUG] Unset Multi-assistant UI client error cb");
-
+       int ret = MA_ERROR_NONE;
        ma_state_e state;
+       ret = __ma_ui_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
-       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
-               MAUI_SLOGE("[ERROR] A handle is not available"); //LCOV_EXCL_LINE
-               return MA_ERROR_INVALID_STATE;
-       }
+       MAUI_SLOGD("[UI DEBUG] Unset Multi-assistant UI client error cb");
 
        /* check state */
        if (state != MA_STATE_INITIALIZED) {
@@ -937,10 +859,10 @@ int ma_ui_unset_error_cb(void)
 
 int ma_ui_set_asr_result_cb(ma_ui_asr_result_cb callback, void* user_data)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_ui_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        MAUI_SLOGD("[UI] Set a ASR result callback");
 
@@ -949,12 +871,6 @@ int ma_ui_set_asr_result_cb(ma_ui_asr_result_cb callback, void* user_data)
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
-               MAUI_SLOGE("[UI ERROR] A handle is not available");
-               return MA_ERROR_INVALID_STATE;
-       }
-
        /* check state */
        if (MA_STATE_INITIALIZED!= state) {
                MAUI_SLOGE("[UI ERROR] Invalid state: Current state is not 'Initialized' (%d)", state);
@@ -968,19 +884,13 @@ int ma_ui_set_asr_result_cb(ma_ui_asr_result_cb callback, void* user_data)
 
 int ma_ui_unset_asr_result_cb(void)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_ui_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        MAUI_SLOGD("[UI] Set a default assistant");
 
-       ma_state_e state;
-       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
-               MAUI_SLOGE("[UI ERROR] A handle is not available");
-               return MA_ERROR_INVALID_STATE;
-       }
-
        /* check state */
        if (MA_STATE_INITIALIZED!= state) {
                MAUI_SLOGE("[UI ERROR] Invalid state: Current state is not 'Initialized' (%d)", state);
@@ -994,10 +904,10 @@ int ma_ui_unset_asr_result_cb(void)
 
 int ma_ui_set_result_cb(ma_ui_result_cb callback, void* user_data)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_ui_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        MAUI_SLOGD("[UI] Set a default assistant");
 
@@ -1006,12 +916,6 @@ int ma_ui_set_result_cb(ma_ui_result_cb callback, void* user_data)
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
-               MAUI_SLOGE("[UI ERROR] A handle is not available");
-               return MA_ERROR_INVALID_STATE;
-       }
-
        /* check state */
        if (MA_STATE_INITIALIZED!= state) {
                MAUI_SLOGE("[UI ERROR] Invalid state: Current state is not 'Initialized' (%d)", state);
@@ -1025,19 +929,13 @@ int ma_ui_set_result_cb(ma_ui_result_cb callback, void* user_data)
 
 int ma_ui_unset_result_cb(void)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_ui_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        MAUI_SLOGD("[UI] Set a default assistant");
 
-       ma_state_e state;
-       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
-               MAUI_SLOGE("[UI ERROR] A handle is not available");
-               return MA_ERROR_INVALID_STATE;
-       }
-
        /* check state */
        if (MA_STATE_INITIALIZED!= state) {
                MAUI_SLOGE("[UI ERROR] Invalid state: Current state is not 'Initialized' (%d)", state);
@@ -1051,10 +949,10 @@ int ma_ui_unset_result_cb(void)
 
 int ma_ui_set_change_assistant_cb(ma_ui_change_assistant_cb callback, void* user_data)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_ui_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        MAUI_SLOGD("[UI] Set a default assistant");
 
@@ -1063,12 +961,6 @@ int ma_ui_set_change_assistant_cb(ma_ui_change_assistant_cb callback, void* user
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
-               MAUI_SLOGE("[UI ERROR] A handle is not available");
-               return MA_ERROR_INVALID_STATE;
-       }
-
        /* check state */
        if (MA_STATE_INITIALIZED!= state) {
                MAUI_SLOGE("[UI ERROR] Invalid state: Current state is not 'Initialized' (%d)", state);
@@ -1082,19 +974,13 @@ int ma_ui_set_change_assistant_cb(ma_ui_change_assistant_cb callback, void* user
 
 int ma_ui_unset_change_assistant_cb(void)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_ui_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        MAUI_SLOGD("[UI] Set a default assistant");
 
-       ma_state_e state;
-       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
-               MAUI_SLOGE("[UI ERROR] A handle is not available");
-               return MA_ERROR_INVALID_STATE;
-       }
-
        /* check state */
        if (MA_STATE_INITIALIZED!= state) {
                MAUI_SLOGE("[UI ERROR] Invalid state: Current state is not 'Initialized' (%d)", state);
@@ -1108,22 +994,16 @@ int ma_ui_unset_change_assistant_cb(void)
 
 int ma_ui_set_recognition_result_cb(ma_ui_recognition_result_cb callback, void* user_data)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_ui_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (NULL == callback) {
                MAUI_SLOGE("[UI ERROR] Invalid parameter");
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
-               MAUI_SLOGE("[UI ERROR] A handle is not available");
-               return MA_ERROR_INVALID_STATE;
-       }
-
        /* check state */
        if (MA_STATE_INITIALIZED!= state) {
                MAUI_SLOGE("[UI ERROR] Invalid state: Current state is not 'Initialized' (%d)", state);
@@ -1137,19 +1017,13 @@ int ma_ui_set_recognition_result_cb(ma_ui_recognition_result_cb callback, void*
 
 int ma_ui_unset_recognition_result_cb(void)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_ui_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        MAUI_SLOGD("[UI] Set a default assistant");
 
-       ma_state_e state;
-       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
-               MAUI_SLOGE("[UI ERROR] A handle is not available");
-               return MA_ERROR_INVALID_STATE;
-       }
-
        /* check state */
        if (MA_STATE_INITIALIZED!= state) {
                MAUI_SLOGE("[UI ERROR] Invalid state: Current state is not 'Initialized' (%d)", state);
@@ -1163,22 +1037,16 @@ int ma_ui_unset_recognition_result_cb(void)
 
 int ma_ui_set_enable_common_ui_cb(ma_ui_enable_common_ui_cb callback, void* user_data)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_ui_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        if (NULL == callback) {
                MAUI_SLOGE("[UI ERROR] Invalid parameter");
                return MA_ERROR_INVALID_PARAMETER;
        }
 
-       ma_state_e state;
-       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
-               MAUI_SLOGE("[UI ERROR] A handle is not available");
-               return MA_ERROR_INVALID_STATE;
-       }
-
        /* check state */
        if (MA_STATE_INITIALIZED != state) {
                MAUI_SLOGE("[UI ERROR] Invalid state: Current state is not 'Initialized' (%d)", state);
@@ -1192,19 +1060,13 @@ int ma_ui_set_enable_common_ui_cb(ma_ui_enable_common_ui_cb callback, void* user
 
 int ma_ui_unset_enable_common_ui_cb(void)
 {
-       if (0 != __ma_ui_get_feature_enabled()) {
-               MAUI_SLOGD("@@@ [UI] not supported");
-               return MA_ERROR_NOT_SUPPORTED;
-       }
+       int ret = MA_ERROR_NONE;
+       ma_state_e state;
+       ret = __ma_ui_validate_client(false, true, &state);
+       if (MA_ERROR_NONE != ret) return ret;
 
        MAUI_SLOGD("[UI] Set a default assistant");
 
-       ma_state_e state;
-       if (0 != ma_ui_client_get_client_state(g_ma_ui, &state)) {
-               MAUI_SLOGE("[UI ERROR] A handle is not available");
-               return MA_ERROR_INVALID_STATE;
-       }
-
        /* check state */
        if (MA_STATE_INITIALIZED != state) {
                MAUI_SLOGE("[UI ERROR] Invalid state: Current state is not 'Initialized' (%d)", state);