Fix bug about privilege check 25/82425/4 accepted/tizen/common/20160805.130054 accepted/tizen/ivi/20160805.111831 accepted/tizen/mobile/20160805.111731 accepted/tizen/tv/20160805.111748 accepted/tizen/wearable/20160805.111815 submit/tizen/20160805.054246
authorKwangyoun Kim <ky85.kim@samsung.com>
Wed, 3 Aug 2016 08:37:34 +0000 (17:37 +0900)
committerKwangyoun Kim <ky85.kim@samsung.com>
Fri, 5 Aug 2016 04:54:50 +0000 (13:54 +0900)
Add dbus error handling
Support MSF/BT audio recording policy

Change-Id: I0852ef36e220d79757545a91ed214fec007b03c8

client/vc.c
client/vc_dbus.c
common/vc_command.c
server/vcd_recorder.c

index 7ddecc3..b2e86fc 100644 (file)
@@ -42,11 +42,6 @@ static int g_feature_enabled = -1;
 static int g_privilege_allowed = -1;
 static cynara *p_cynara = NULL;
 
-#if 0
-static Ecore_Event_Handler* g_focus_in_hander = NULL;
-static Ecore_Event_Handler* g_focus_out_hander = NULL;
-#endif
-
 Eina_Bool __vc_notify_state_changed(void *data);
 Eina_Bool __vc_notify_error(void *data);
 
@@ -92,13 +87,14 @@ static int __check_privilege_initialize()
 static int __check_privilege(const char* uid, const char * privilege)
 {
        FILE *fp = NULL;
-       char smack_label[1024] = "/proc/self/attr/current";
+       char label_path[1024] = "/proc/self/attr/current";
+       char smack_label[1024] = {'\0',};
 
        if (!p_cynara) {
            return false;
        }
 
-       fp = fopen(smack_label, "r");
+       fp = fopen(label_path, "r");
        if (fp != NULL) {
            if (fread(smack_label, 1, sizeof(smack_label), fp) <= 0)
                SLOG(LOG_ERROR, TAG_VCC, "[ERROR] fail to fread");
@@ -365,12 +361,6 @@ static void __vc_internal_unprepare(void)
                SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request finalize : %s", __vc_get_error_code(ret));
        }
 
-
-#if 0
-       ecore_event_handler_del(g_focus_in_hander);
-       ecore_event_handler_del(g_focus_out_hander);
-#endif
-
        vc_cmd_parser_delete_file(getpid(), VC_COMMAND_TYPE_FOREGROUND);
        vc_cmd_parser_delete_file(getpid(), VC_COMMAND_TYPE_BACKGROUND);
 
@@ -432,78 +422,6 @@ int vc_deinitialize(void)
        return VC_ERROR_NONE;
 }
 
-#if 0
-static Eina_Bool __vc_x_event_window_focus_in(void *data, int type, void *event)
-{
-       Ecore_X_Event_Window_Focus_In *e;
-
-       e = event;
-
-       int xid = -1;
-       if (0 != vc_client_get_xid(g_vc, &xid)) {
-               SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get current xid");
-               return ECORE_CALLBACK_PASS_ON;
-       }
-
-       if (e->win == (Ecore_X_Window)xid) {
-               SLOG(LOG_DEBUG, TAG_VCC, "Focus in : pid(%d) xid(%d)", getpid(), xid);
-               int ret = vc_config_mgr_set_foreground(getpid(), true);
-               if (0 != ret) {
-                       ret = vc_config_convert_error_code((vc_config_error_e)ret);
-                       SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set focus in : %s", __vc_get_error_code(ret));
-               }
-               /* set authority valid */
-               vc_auth_state_e state = VC_AUTH_STATE_NONE;
-               if (0 != vc_client_get_auth_state(g_vc, &state)) {
-                       SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get auth state");
-               }
-               if (VC_AUTH_STATE_INVALID == state) {
-                       vc_client_set_auth_state(g_vc, VC_AUTH_STATE_VALID);
-
-                       /* notify auth changed cb */
-                       ecore_timer_add(0, __notify_auth_changed_cb, NULL);
-               }
-       }
-
-       return ECORE_CALLBACK_PASS_ON;
-}
-
-static Eina_Bool __vc_x_event_window_focus_out(void *data, int type, void *event)
-{
-       Ecore_X_Event_Window_Focus_In *e;
-
-       e = event;
-
-       int xid = -1;
-       if (0 != vc_client_get_xid(g_vc, &xid)) {
-               SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get current xid");
-               return ECORE_CALLBACK_PASS_ON;
-       }
-
-       if (e->win == (Ecore_X_Window)xid) {
-               SLOG(LOG_DEBUG, TAG_VCC, "Focus out : pid(%d) xid(%d)", getpid(), xid);
-               int ret = vc_config_mgr_set_foreground(getpid(), false);
-               if (0 != ret) {
-                       ret = vc_config_convert_error_code((vc_config_error_e)ret);
-                       SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set focus out : %s", __vc_get_error_code(ret));
-               }
-               /* set authority valid */
-               vc_auth_state_e state = VC_AUTH_STATE_NONE;
-               if (0 != vc_client_get_auth_state(g_vc, &state)) {
-                       SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get auth state");
-               }
-               if (VC_AUTH_STATE_VALID == state) {
-                       vc_client_set_auth_state(g_vc, VC_AUTH_STATE_INVALID);
-
-                       /* notify authority changed cb */
-                       ecore_timer_add(0, __notify_auth_changed_cb, NULL);
-               }
-       }
-
-       return ECORE_CALLBACK_PASS_ON;
-}
-#endif
-
 static Eina_Bool __vc_connect_daemon(void *data)
 {
        /* Send hello */
@@ -545,15 +463,38 @@ static Eina_Bool __vc_connect_daemon(void *data)
        vc_client_set_service_state(g_vc, (vc_service_state_e)service_state);
 
        g_connect_timer = NULL;
-#if 0
-       g_focus_in_hander = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_FOCUS_IN, __vc_x_event_window_focus_in, NULL);
-       g_focus_out_hander = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_FOCUS_OUT, __vc_x_event_window_focus_out, NULL);
-#else
+
        ret = aul_add_status_local_cb(__vc_app_state_changed_cb, NULL);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set app stae changed callback");
        }
-#endif
+
+       int status = aul_app_get_status_bypid(getpid());
+       if (STATUS_FOCUS == status || STATUS_VISIBLE == status) {
+               SLOG(LOG_DEBUG, TAG_VCC, "===== Set foreground");
+               ret = vc_dbus_set_foreground(getpid(), true);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set foreground (true) : %d", ret);
+               }
+
+               ret = vc_client_set_is_foreground(g_vc, true);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to save is_foreground (true) : %d", ret);
+               }
+
+               /* set authority valid */
+               vc_auth_state_e state = VC_AUTH_STATE_NONE;
+               if (0 != vc_client_get_auth_state(g_vc, &state)) {
+                       SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get auth state");
+               }
+               if (VC_AUTH_STATE_INVALID == state) {
+                       vc_client_set_auth_state(g_vc, VC_AUTH_STATE_VALID);
+
+                       /* notify auth changed cb */
+                       ecore_idler_add(__notify_auth_changed_cb, NULL);
+               }
+       }
+
        vc_client_set_client_state(g_vc, VC_STATE_READY);
        ecore_timer_add(0, __vc_notify_state_changed, g_vc);
 
@@ -810,99 +751,6 @@ int vc_get_service_state(vc_service_state_e* state)
        return VC_ERROR_NONE;
 }
 
-#if 0
-int vc_set_window_id(int wid)
-{
-       SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Set Window id");
-
-       if (0 >= wid) {
-               SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Input parameter is invalid");
-               SLOG(LOG_DEBUG, TAG_VCC, "=====");
-               SLOG(LOG_DEBUG, TAG_VCC, " ");
-               return VC_ERROR_INVALID_PARAMETER;
-       }
-
-       vc_state_e state;
-       if (0 != vc_client_get_client_state(g_vc, &state)) {
-               SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
-               SLOG(LOG_DEBUG, TAG_VCC, "=====");
-               SLOG(LOG_DEBUG, TAG_VCC, " ");
-               return VC_ERROR_INVALID_STATE;
-       }
-
-       /* check state */
-       if (state != VC_STATE_READY) {
-               SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: Current state is not 'READY'");
-               SLOG(LOG_DEBUG, TAG_VCC, "=====");
-               SLOG(LOG_DEBUG, TAG_VCC, " ");
-               return VC_ERROR_INVALID_STATE;
-       }
-
-       if (0 != vc_client_set_xid(g_vc, wid)) {
-               SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not valid");
-               SLOG(LOG_DEBUG, TAG_VCC, "=====");
-               SLOG(LOG_DEBUG, TAG_VCC, " ");
-               return VC_ERROR_INVALID_STATE;
-       }
-
-       /* Check if current xid is top window */
-       int ret = -1;
-       if ((Ecore_X_Window)wid == ecore_x_window_focus_get()) {
-               /* Set current pid */
-               ret = vc_config_mgr_set_foreground(getpid(), true);
-               if (0 != ret) {
-                       ret = vc_config_convert_error_code((vc_config_error_e)ret);
-                       SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set focus in : %s", __vc_get_error_code(ret));
-               }
-       }
-
-       SLOG(LOG_DEBUG, TAG_VCC, "=====");
-       SLOG(LOG_DEBUG, TAG_VCC, " ");
-
-       return ret;
-}
-
-int vc_get_window_id(int* wid)
-{
-       SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] Get Window id");
-
-       if (NULL == wid) {
-               SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Input parameter is NULL");
-               SLOG(LOG_DEBUG, TAG_VCC, "=====");
-               SLOG(LOG_DEBUG, TAG_VCC, " ");
-               return VC_ERROR_INVALID_PARAMETER;
-       }
-
-       vc_state_e state;
-       if (0 != vc_client_get_client_state(g_vc, &state)) {
-               SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available");
-               SLOG(LOG_DEBUG, TAG_VCC, "=====");
-               SLOG(LOG_DEBUG, TAG_VCC, " ");
-               return VC_ERROR_INVALID_STATE;
-       }
-
-       /* check state */
-       if (state != VC_STATE_READY) {
-               SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: Current state is not 'READY'");
-               SLOG(LOG_DEBUG, TAG_VCC, "=====");
-               SLOG(LOG_DEBUG, TAG_VCC, " ");
-               return VC_ERROR_INVALID_STATE;
-       }
-
-       if (0 != vc_client_get_xid(g_vc, wid)) {
-               SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not valid");
-               SLOG(LOG_DEBUG, TAG_VCC, "=====");
-               SLOG(LOG_DEBUG, TAG_VCC, " ");
-               return VC_ERROR_INVALID_STATE;
-       }
-
-       SLOG(LOG_DEBUG, TAG_VCC, "=====");
-       SLOG(LOG_DEBUG, TAG_VCC, " ");
-
-       return VC_ERROR_NONE;
-}
-#endif
-
 /**
 * @brief Checks whether the command format is supported.
 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
@@ -1156,7 +1004,6 @@ int vc_set_exclusive_command_option(bool value)
                return ret;
        }
 
-       /* Check if current xid is top window */
        int count = 0;
        do {
                ret = vc_dbus_request_set_exclusive_command(g_vc->handle, value);
index 2f8ca3d..22171c5 100644 (file)
@@ -307,8 +307,21 @@ int vc_dbus_reconnect()
        return 0;
 }
 
+static int __dbus_check()
+{
+       if (NULL == g_conn_sender) {
+               SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection");
+               return vc_dbus_reconnect();
+       }
+       return 0;
+}
+
 int vc_dbus_request_hello()
 {
+       if (0 != __dbus_check()) {
+               return VC_ERROR_OPERATION_FAILED;
+       }
+
        DBusMessage* msg;
 
        msg = dbus_message_new_method_call(
@@ -349,6 +362,10 @@ int vc_dbus_request_hello()
 
 int vc_dbus_request_initialize(int pid, int* mgr_pid, int* service_state)
 {
+       if (0 != __dbus_check()) {
+               return VC_ERROR_OPERATION_FAILED;
+       }
+
        DBusMessage* msg;
 
        msg = dbus_message_new_method_call(
@@ -417,6 +434,10 @@ int vc_dbus_request_initialize(int pid, int* mgr_pid, int* service_state)
 
 int vc_dbus_request_finalize(int pid)
 {
+       if (0 != __dbus_check()) {
+               return VC_ERROR_OPERATION_FAILED;
+       }
+
        DBusMessage* msg;
 
        msg = dbus_message_new_method_call(
@@ -477,6 +498,10 @@ int vc_dbus_request_finalize(int pid)
 
 int vc_dbus_request_set_exclusive_command(int pid, bool value)
 {
+       if (0 != __dbus_check()) {
+               return VC_ERROR_OPERATION_FAILED;
+       }
+
        DBusMessage* msg;
 
        msg = dbus_message_new_method_call(
@@ -541,6 +566,10 @@ int vc_dbus_request_set_exclusive_command(int pid, bool value)
 
 int vc_dbus_request_set_command(int pid, vc_cmd_type_e cmd_type)
 {
+       if (0 != __dbus_check()) {
+               return VC_ERROR_OPERATION_FAILED;
+       }
+
        DBusMessage* msg;
 
        msg = dbus_message_new_method_call(
@@ -603,6 +632,10 @@ int vc_dbus_request_set_command(int pid, vc_cmd_type_e cmd_type)
 
 int vc_dbus_request_unset_command(int pid, vc_cmd_type_e cmd_type)
 {
+       if (0 != __dbus_check()) {
+               return VC_ERROR_OPERATION_FAILED;
+       }
+
        DBusMessage* msg;
 
        msg = dbus_message_new_method_call(
@@ -665,6 +698,10 @@ int vc_dbus_request_unset_command(int pid, vc_cmd_type_e cmd_type)
 
 int vc_dbus_set_foreground(int pid, bool value)
 {
+       if (0 != __dbus_check()) {
+               return VC_ERROR_OPERATION_FAILED;
+       }
+
        DBusMessage* msg = NULL;
        int tmp_value = 0;
 
@@ -921,6 +958,10 @@ int vc_dbus_request_cancel(int pid)
 /* Authority */
 int vc_dbus_request_auth_enable(int pid, int mgr_pid)
 {
+       if (0 != __dbus_check()) {
+               return VC_ERROR_OPERATION_FAILED;
+       }
+
        DBusMessage* msg;
 
        char service_name[64] = {0,};
@@ -991,6 +1032,10 @@ int vc_dbus_request_auth_enable(int pid, int mgr_pid)
 
 int vc_dbus_request_auth_disable(int pid, int mgr_pid)
 {
+       if (0 != __dbus_check()) {
+               return VC_ERROR_OPERATION_FAILED;
+       }
+
        DBusMessage* msg;
 
        char service_name[64] = {0,};
@@ -1061,6 +1106,10 @@ int vc_dbus_request_auth_disable(int pid, int mgr_pid)
 
 int vc_dbus_request_auth_start(int pid, int mgr_pid)
 {
+       if (0 != __dbus_check()) {
+               return VC_ERROR_OPERATION_FAILED;
+       }
+
        DBusMessage* msg;
 
        char service_name[64] = {0,};
@@ -1133,6 +1182,10 @@ int vc_dbus_request_auth_start(int pid, int mgr_pid)
 
 int vc_dbus_request_auth_stop(int pid, int mgr_pid)
 {
+       if (0 != __dbus_check()) {
+               return VC_ERROR_OPERATION_FAILED;
+       }
+
        DBusMessage* msg;
 
        char service_name[64] = {0,};
@@ -1203,6 +1256,10 @@ int vc_dbus_request_auth_stop(int pid, int mgr_pid)
 
 int vc_dbus_request_auth_cancel(int pid, int mgr_pid)
 {
+       if (0 != __dbus_check()) {
+               return VC_ERROR_OPERATION_FAILED;
+       }
+
        DBusMessage* msg;
 
        char service_name[64] = {0,};
index ef433d4..4d5fa9f 100644 (file)
@@ -75,13 +75,14 @@ static int __check_privilege_initialize()
 static int __check_privilege(const char* uid, const char * privilege)
 {
        FILE *fp = NULL;
-       char smack_label[1024] = "/proc/self/attr/current";
+       char label_path[1024] = "/proc/self/attr/current";
+       char smack_label[1024] = {'\0',};
 
        if (!p_cynara) {
            return false;
        }
 
-       fp = fopen(smack_label, "r");
+       fp = fopen(label_path, "r");
        if (fp != NULL) {
            if (fread(smack_label, 1, sizeof(smack_label), fp) <= 0)
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] fail to fread");
index 4996cea..6c87c63 100644 (file)
@@ -82,11 +82,15 @@ static float get_volume_decibel(char* data, int size);
 #ifdef TV_MSF_WIFI_MODE
 static void __msf_wifi_audio_data_receive_cb(msf_wifi_voice_data_s *voice_data, void* user_data)
 {
-       if (VCD_RECORDER_STATE_RECORDING != g_recorder_state) {
-               /*SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Exit audio reading normal func");*/
+       if (0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_MSF, sizeof(VCP_AUDIO_ID_MSF))){
+               SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] current audio type is (%s)", g_current_audio_type);
                return;
        }
 
+       if (VCD_RECORDER_STATE_RECORDING != g_recorder_state) {
+               SLOG(LOG_WARN, TAG_VCD, "[Recorder] Not start yet, but send audio data vi MSF");
+       }
+
        if (NULL != g_audio_cb) {
                if (0 != g_audio_cb((void*)voice_data->audio_buf, (unsigned int)voice_data->length)) {
                        SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to read audio");
@@ -135,11 +139,15 @@ static void _bt_cb_hid_state_changed(int result, bool connected, const char *rem
 
 static void _bt_hid_audio_data_receive_cb(bt_hid_voice_data_s *voice_data, void *user_data)
 {
-       if (VCD_RECORDER_STATE_RECORDING != g_recorder_state) {
-               /*SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Exit audio reading normal func");*/
+       if (0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_BLUETOOTH, sizeof(VCP_AUDIO_ID_BLUETOOTH))){
+               SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] current audio type is (%s)", g_current_audio_type);
                return;
        }
 
+       if (VCD_RECORDER_STATE_RECORDING != g_recorder_state) {
+               SLOG(LOG_WARN, TAG_VCD, "[Recorder] Not start yet, but send audio data vi Bluetooth");
+       }
+
        if (NULL != g_audio_cb) {
                if (0 != g_audio_cb((void*)voice_data->audio_buf, (unsigned int)voice_data->length)) {
                        SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to read audio");