Add to check if app agreed or not
[platform/core/uifw/tts.git] / server / ttsd_server.c
index cdd6e9b..c49a7bd 100644 (file)
@@ -11,6 +11,7 @@
 *  limitations under the License.
 */
 
+#include <app_manager.h>
 #include <aul.h>
 #include <Ecore.h>
 
@@ -297,7 +298,7 @@ int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int d
        return TTSD_ERROR_NONE;
 }
 
-bool __get_client_cb(int pid, int uid, app_state_e state, void* user_data)
+bool __get_client_cb(int pid, int uid, app_tts_state_e state, void* user_data)
 {
        /* clear client data */
        ttsd_data_clear_data(uid);
@@ -406,7 +407,7 @@ void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_
        return;
 }
 
-bool __terminate_client(int pid, int uid, app_state_e state, void* user_data)
+bool __terminate_client(int pid, int uid, app_tts_state_e state, void* user_data)
 {
        SLOG(LOG_INFO, tts_tag(), "@@@ Start to terminate client [%d]", uid);
        ttsd_server_finalize(uid);
@@ -523,9 +524,29 @@ int ttsd_server_initialize(int pid, int uid, bool* credential_needed)
        }
 
        if (0 != ttsd_engine_agent_is_credential_needed(uid, credential_needed)) {
-               SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to get credential necessity");
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get credential necessity");
                return TTSD_ERROR_OPERATION_FAILED;
        }
+
+       char* appid = NULL;
+       if (0 != app_manager_get_app_id(pid, &appid)) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id, pid(%d)", pid);
+       }
+       bool is_agreed = false;
+       if (0 != ttsd_engine_check_app_agreed(appid, &is_agreed)) {
+               SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to check app agreed");
+               if (!appid)
+                       free(appid);
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
+       if (!appid)
+               free(appid);
+
+       if (false == is_agreed) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
+               return TTSD_ERROR_PERMISSION_DENIED;
+       }
+
        if (0 != ttsd_data_new_client(pid, uid)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add client info");
                return TTSD_ERROR_OPERATION_FAILED;
@@ -584,7 +605,7 @@ static void __read_proc()
        return;
 }
 
-bool __get_client_for_clean_up(int pid, int uid, app_state_e state, void* user_data)
+bool __get_client_for_clean_up(int pid, int uid, app_tts_state_e state, void* user_data)
 {
        bool exist = false;
        int i = 0;
@@ -661,7 +682,7 @@ int ttsd_server_finalize(int uid)
 {
        SLOG(LOG_INFO, tts_tag(), "[Server] Server finalize");
 
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid");
        }
@@ -690,7 +711,7 @@ int ttsd_server_finalize(int uid)
 
 int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id, const char* credential)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_add_queue : uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -809,7 +830,7 @@ Eina_Bool __send_interrupt_client(void *data)
 
 int ttsd_server_play(int uid, const char* credential)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid  ", uid);
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -892,7 +913,7 @@ int ttsd_server_play(int uid, const char* credential)
 
 int ttsd_server_stop(int uid)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -926,7 +947,7 @@ int ttsd_server_stop(int uid)
 
 int ttsd_server_pause(int uid, int* utt_id)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_pause : uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -954,7 +975,7 @@ int ttsd_server_pause(int uid, int* utt_id)
 
 int ttsd_server_get_support_voices(int uid, GList** voice_list)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -974,7 +995,7 @@ int ttsd_server_get_support_voices(int uid, GList** voice_list)
 
 int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_get_current_voice : uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -994,7 +1015,7 @@ int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
 
 int ttsd_server_set_private_data(int uid, const char* key, const char* data)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid", uid);
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -1017,7 +1038,7 @@ int ttsd_server_set_private_data(int uid, const char* key, const char* data)
 
 int ttsd_server_get_private_data(int uid, const char* key, char** data)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid", uid);
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -1066,7 +1087,7 @@ int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback)
 
 int ttsd_server_play_pcm(int uid)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid  ", uid);
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -1125,7 +1146,7 @@ int ttsd_server_play_pcm(int uid)
 
 int ttsd_server_stop_pcm(int uid)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;