From ff65c8eed642e1b8d4b8c32183c234df8b91221c Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Thu, 11 May 2017 18:15:33 +0900 Subject: [PATCH 01/16] Fix memory leak Change-Id: I6d8d02a895d84e9a9469930aef3dd2e198a30983 Signed-off-by: Suyeon Hwang --- common/vc_cmd_db.c | 50 +++++++++++++++++++++++++++++++----------------- common/vc_command.c | 1 - server/vcd_client_data.c | 8 ++++++++ server/vcd_dbus.c | 25 ++++++++++++++++++++---- server/vcd_recorder.c | 2 +- 5 files changed, 62 insertions(+), 24 deletions(-) diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index 30e0266..2e35e84 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -22,7 +22,7 @@ #include "vc_cmd_db.h" #include "vc_main.h" -#include "voice_control_command.h" +#include "vc_command.h" #include "voice_control_command_expand.h" @@ -361,10 +361,12 @@ static int __vc_db_get_commands(int pid, vc_cmd_type_e type, GSList** cmd_list) while (SQLITE_ROW == ret) { int temp = 0; + int ret = -1; char* temp_text = NULL; - vc_cmd_s* temp_cmd = NULL; - temp_cmd = (vc_cmd_s*)calloc(1, sizeof(vc_cmd_s)); - if (NULL == temp_cmd) { + vc_cmd_h temp_cmd; + ret = vc_cmd_create(&temp_cmd); + + if (0 != ret) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to allocate memory"); if (NULL != appid) { free(appid); @@ -380,12 +382,16 @@ static int __vc_db_get_commands(int pid, vc_cmd_type_e type, GSList** cmd_list) temp_text = (char*)sqlite3_column_text(stmt, 7); if (NULL != temp_text) - temp_cmd->appid = strdup(temp_text); + vc_cmd_set_appid(temp_cmd, temp_text); - if (NULL != appid && NULL != temp_cmd->appid) { - if (VC_COMMAND_TYPE_BACKGROUND == type && 0 == strncmp(appid, temp_cmd->appid, strlen(appid))) { + ret = vc_cmd_get_appid(temp_cmd, &temp_text); + if (NULL != appid && 0 == ret) { + if (VC_COMMAND_TYPE_BACKGROUND == type && 0 == strncmp(appid, temp_text, strlen(appid))) { SLOG(LOG_DEBUG, vc_db_tag(), "Skip get background commands when app is foreground, appid(%s)", appid); + free(temp_text); + temp_text = NULL; + ret = sqlite3_step(stmt); if (SQLITE_DONE == ret) break; @@ -394,41 +400,49 @@ static int __vc_db_get_commands(int pid, vc_cmd_type_e type, GSList** cmd_list) } } + if (NULL != temp_text) { + free(temp_text); + temp_text = NULL; + } + temp = sqlite3_column_int(stmt, 0); - temp_cmd->id = temp; + vc_cmd_set_id(temp_cmd, temp); temp = sqlite3_column_int(stmt, 1); - temp_cmd->pid = temp; + vc_cmd_set_pid(temp_cmd, temp); temp = sqlite3_column_int(stmt, 2); - temp_cmd->type = temp; + vc_cmd_set_type(temp_cmd, temp); temp = sqlite3_column_int(stmt, 3); - temp_cmd->format = temp; + vc_cmd_set_format(temp_cmd, temp); temp = sqlite3_column_int(stmt, 4); - temp_cmd->domain = temp; + vc_cmd_set_domain(temp_cmd, temp); temp_text = (char*)sqlite3_column_text(stmt, 5); if (NULL != temp_text) - temp_cmd->command = strdup(temp_text); + vc_cmd_set_command(temp_cmd, temp_text); temp_text = (char*)sqlite3_column_text(stmt, 6); if (NULL != temp_text) - temp_cmd->parameter = strdup(temp_text); + vc_cmd_set_unfixed_command(temp_cmd, temp_text); temp_text = (char*)sqlite3_column_text(stmt, 8); if (NULL != temp_text) - temp_cmd->invocation_name = strdup(temp_text); + vc_cmd_set_invocation_name(temp_cmd, temp_text); temp_text = (char*)sqlite3_column_text(stmt, 9); if (NULL != temp_text) - temp_cmd->fixed = strdup(temp_text); + vc_cmd_set_fixed_command(temp_cmd, temp_text); - if (type == temp_cmd->type) { + ret = vc_cmd_get_type(temp_cmd, &temp); + if (0 == ret && type == temp) { *cmd_list = g_slist_append(*cmd_list, temp_cmd); } else { - SLOG(LOG_WARN, vc_db_tag(), "[WARNING] Command type(%d) is NOT valid : request type(%d)", temp_cmd->type, type); + SLOG(LOG_WARN, vc_db_tag(), "[WARNING] Command type(%d) is NOT valid : request type(%d)", temp, type); + + vc_cmd_destroy((vc_cmd_h)temp_cmd); } ret = sqlite3_step(stmt); if (SQLITE_DONE == ret) diff --git a/common/vc_command.c b/common/vc_command.c index 38f0299..1478fcd 100644 --- a/common/vc_command.c +++ b/common/vc_command.c @@ -702,7 +702,6 @@ int vc_cmd_create(vc_cmd_h* vc_command) command->key = VC_KEY_NONE; command->modifier = VC_MODIFIER_NONE; command->invocation_name = NULL; - command->parameter = NULL; command->appid = NULL; command->fixed = NULL; diff --git a/server/vcd_client_data.c b/server/vcd_client_data.c index b033950..e7a9a00 100644 --- a/server/vcd_client_data.c +++ b/server/vcd_client_data.c @@ -942,6 +942,10 @@ int vcd_client_add(int pid) if (NULL == g_client_list) { SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to add new client"); + + free(info); + info = NULL; + return -1; } else { SLOG(LOG_DEBUG, TAG_VCD, "[Client Data SUCCESS] Add new client"); @@ -1263,6 +1267,10 @@ int vcd_client_widget_add(int pid) if (NULL == g_widget_list) { SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to add new widget"); + + free(info); + info = NULL; + return -1; } else { SLOG(LOG_DEBUG, TAG_VCD, "[Client Data SUCCESS] Add new widget"); diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index 75a8c63..eed98a8 100644 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -613,10 +613,17 @@ int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char* SLOG(LOG_DEBUG, TAG_VCD, "[Dbus] send dialog : pid(%d), disp_text(%s), utt_text(%s), continue(%d)", pid, disp_text, utt_text, continuous); - if (NULL == disp_text) - disp_text = strdup("#NULL"); - if (NULL == utt_text) - utt_text = strdup("#NULL"); + char* disp_null = NULL; + char* utt_null = NULL; + if (NULL == disp_text) { + disp_null = strdup("#NULL"); + disp_text = disp_null; + } + + if (NULL == utt_text) { + utt_null = strdup("#NULL"); + utt_text = utt_null; + } dbus_message_append_args(msg, DBUS_TYPE_INT32, &pid, @@ -637,6 +644,16 @@ int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char* dbus_message_unref(msg); + if (NULL != disp_null) { + free(disp_null); + disp_null = NULL; + } + + if (NULL != utt_null) { + free(utt_null); + utt_null = NULL; + } + return 0; } diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index 6202720..25df611 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -754,7 +754,7 @@ int vcd_recorder_stop() #endif } - if (0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_NONE, sizeof(VCP_AUDIO_ID_NONE))) { + if (NULL != g_current_audio_type && 0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_NONE, sizeof(VCP_AUDIO_ID_NONE))) { vcd_recorder_set(VCP_AUDIO_ID_NONE, VCP_AUDIO_TYPE_PCM_S16_LE, 16000, 1); vcd_engine_set_audio_type(VCP_AUDIO_ID_NONE); } -- 2.7.4 From 28ec881df62d707cf7ba5001609205ed5d7b672a Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Fri, 19 May 2017 11:19:28 +0900 Subject: [PATCH 02/16] Fix invalid access when error message is NULL Change-Id: If46596e96d2f24660e04b1fb4896c36f29fdc244 --- server/vcd_server.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/vcd_server.c b/server/vcd_server.c index bed1370..9242c83 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -900,7 +900,11 @@ static void __vcd_server_error_cb(vcp_error_e error, const char* msg, void *user ecore_main_loop_thread_safe_call_async(__cancel_by_error, NULL); char* error_msg = NULL; - error_msg = strdup(msg); + if (NULL != msg) { + error_msg = strdup(msg); + } else { + error_msg = strdup("no message"); + } if (0 != vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), error, error_msg)) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send error signal"); -- 2.7.4 From 99eb889e3af8784d5123249b5c903e9d4cd6fcd4 Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Fri, 19 May 2017 14:06:02 +0900 Subject: [PATCH 03/16] Change instant error message to NULL Change-Id: I5513aa24edbd8d6b6b3626ee12b0dd25bb891224 --- client/vc_mgr_dbus.c | 14 +++++++++++--- server/vcd_dbus.c | 25 ++++++++++++++++++------- server/vcd_server.c | 2 -- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/client/vc_mgr_dbus.c b/client/vc_mgr_dbus.c index 06175e3..dde3532 100644 --- a/client/vc_mgr_dbus.c +++ b/client/vc_mgr_dbus.c @@ -261,7 +261,7 @@ static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd SLOG(LOG_DEBUG, TAG_VCM, "===== Get Error"); int reason; int daemon_pid; - char* err_msg; + char* err_msg = NULL; dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &reason, @@ -273,8 +273,16 @@ static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd SLOG(LOG_ERROR, TAG_VCM, "<<<< vc mgr Get Error message : Get arguments error (%s)", err.message); dbus_error_free(&err); } else { - SLOG(LOG_ERROR, TAG_VCM, "<<<< vc mgr Get Error message : reason(%d), daemon_pid(%d), msg(%s)", reason, daemon_pid, err_msg); - __vc_mgr_cb_error(reason, daemon_pid, err_msg); + char* temp_msg = NULL; + if (NULL != err_msg && strcmp("#NULL", err_msg)) { + temp_msg = strdup(err_msg); + } + SLOG(LOG_ERROR, TAG_VCM, "<<<< vc mgr Get Error message : reason(%d), daemon_pid(%d), msg(%s)", reason, daemon_pid, temp_msg); + __vc_mgr_cb_error(reason, daemon_pid, temp_msg); + if (NULL != temp_msg) { + free(temp_msg); + temp_msg = NULL; + } } SLOG(LOG_DEBUG, TAG_VCM, "====="); diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index eed98a8..45c5e4c 100644 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -661,11 +661,6 @@ int vcdc_send_error_signal_to_manager(int manager_pid, int reason, char *err_msg { SLOG(LOG_ERROR, TAG_VCD, ">>>> Send error signal to manager"); - if (NULL == err_msg) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Input parameter is NULL"); - return VCD_ERROR_INVALID_PARAMETER; - } - if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -686,18 +681,34 @@ int vcdc_send_error_signal_to_manager(int manager_pid, int reason, char *err_msg return VCD_ERROR_OUT_OF_MEMORY; } + char *temp_msg = NULL; + if (NULL == err_msg) { + SLOG(LOG_WARN, TAG_VCD, "[Dbus ERROR] Input parameter is NULL"); + temp_msg = strdup("#NULL"); + } else { + temp_msg = strdup(err_msg); + } + daemon_pid = getpid(); - dbus_message_append_args(msg, DBUS_TYPE_INT32, &reason, DBUS_TYPE_INT32, &daemon_pid, DBUS_TYPE_STRING, &err_msg, DBUS_TYPE_INVALID); + dbus_message_append_args(msg, DBUS_TYPE_INT32, &reason, DBUS_TYPE_INT32, &daemon_pid, DBUS_TYPE_STRING, &temp_msg, DBUS_TYPE_INVALID); if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); + if (NULL != temp_msg) { + free(temp_msg); + temp_msg = NULL; + } return VCD_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_DEBUG, TAG_VCD, "<<<< Send error signal to manager : reason(%d), Error Msg(%s)", reason, err_msg); + SLOG(LOG_DEBUG, TAG_VCD, "<<<< Send error signal to manager : reason(%d), Error Msg(%s)", reason, temp_msg); dbus_connection_flush(g_conn_sender); } dbus_message_unref(msg); + if (NULL != temp_msg) { + free(temp_msg); + temp_msg = NULL; + } return 0; } diff --git a/server/vcd_server.c b/server/vcd_server.c index 9242c83..681ae9f 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -902,8 +902,6 @@ static void __vcd_server_error_cb(vcp_error_e error, const char* msg, void *user char* error_msg = NULL; if (NULL != msg) { error_msg = strdup(msg); - } else { - error_msg = strdup("no message"); } if (0 != vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), error, error_msg)) { -- 2.7.4 From 47705d5c12eafba6747b17402dbd064e4d970599 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 19 May 2017 13:39:00 +0900 Subject: [PATCH 04/16] Fix build dependency The app-control API package is capi-appfw-app-control. Change-Id: I5959c9fe163512c8374c8d331706ca3ef93bed48 Signed-off-by: Hwankyu Jhun --- CMakeLists.txt | 4 ++-- client/vc_mgr.c | 1 - packaging/voice-control.spec | 2 +- server/vcd_server.c | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb246fd..339df7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,12 +42,12 @@ INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/include") INCLUDE(FindPkgConfig) IF("${_TV_PRODUCT}" STREQUAL "TRUE") pkg_check_modules(pkgs REQUIRED - aul capi-appfw-application capi-appfw-app-manager capi-base-common capi-media-audio-io capi-media-sound-manager ecore-wayland + aul capi-appfw-app-control capi-appfw-app-manager capi-base-common capi-media-audio-io capi-media-sound-manager ecore-wayland capi-network-bluetooth capi-system-info cynara-client cynara-session dbus-1 db-util dlog ecore glib-2.0 json-glib-1.0 libtzplatform-config libxml-2.0 sqlite3 vconf msfapi ) ELSE() pkg_check_modules(pkgs REQUIRED - aul capi-appfw-application capi-appfw-app-manager capi-base-common capi-media-audio-io capi-media-sound-manager ecore-wayland + aul capi-appfw-app-control capi-appfw-app-manager capi-base-common capi-media-audio-io capi-media-sound-manager ecore-wayland capi-system-info cynara-client cynara-session dbus-1 db-util dlog ecore glib-2.0 json-glib-1.0 libtzplatform-config libxml-2.0 sqlite3 vconf ) ENDIF() diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 26b1630..b64bdaa 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -14,7 +14,6 @@ * limitations under the License. */ -#include #include #include diff --git a/packaging/voice-control.spec b/packaging/voice-control.spec index 25c0471..1ea14a4 100644 --- a/packaging/voice-control.spec +++ b/packaging/voice-control.spec @@ -11,7 +11,7 @@ Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig BuildRequires: pkgconfig(aul) -BuildRequires: pkgconfig(capi-appfw-application) +BuildRequires: pkgconfig(capi-appfw-app-control) BuildRequires: pkgconfig(capi-appfw-app-manager) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(capi-media-audio-io) diff --git a/server/vcd_server.c b/server/vcd_server.c index 681ae9f..23675a8 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include #include #include -- 2.7.4 From 807585486b2a6e7c25753735e486f6b9e26acdb2 Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Tue, 30 May 2017 11:32:46 +0900 Subject: [PATCH 05/16] Change BT internal APIS Change-Id: Id7c2be600885e62974b61ae757e66477a6001cc7 --- CMakeLists.txt | 2 +- packaging/voice-control.spec | 3 ++- server/vcd_recorder.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 339df7f..86be582 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,7 @@ INCLUDE(FindPkgConfig) IF("${_TV_PRODUCT}" STREQUAL "TRUE") pkg_check_modules(pkgs REQUIRED aul capi-appfw-app-control capi-appfw-app-manager capi-base-common capi-media-audio-io capi-media-sound-manager ecore-wayland - capi-network-bluetooth capi-system-info cynara-client cynara-session dbus-1 db-util dlog ecore glib-2.0 json-glib-1.0 libtzplatform-config libxml-2.0 sqlite3 vconf msfapi + capi-network-bluetooth capi-network-bluetooth-tv capi-system-info cynara-client cynara-session dbus-1 db-util dlog ecore glib-2.0 json-glib-1.0 libtzplatform-config libxml-2.0 sqlite3 vconf msfapi ) ELSE() pkg_check_modules(pkgs REQUIRED diff --git a/packaging/voice-control.spec b/packaging/voice-control.spec index 1ea14a4..4a21c0f 100644 --- a/packaging/voice-control.spec +++ b/packaging/voice-control.spec @@ -16,7 +16,6 @@ BuildRequires: pkgconfig(capi-appfw-app-manager) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(capi-media-audio-io) BuildRequires: pkgconfig(capi-media-sound-manager) -BuildRequires: pkgconfig(capi-network-bluetooth) BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(cynara-session) @@ -31,6 +30,8 @@ BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(sqlite3) %if "%{PRODUCT_TYPE}" == "TV" +BuildRequires: pkgconfig(capi-network-bluetooth) +BuildRequires: pkgconfig(capi-network-bluetooth-tv) BuildRequires: pkgconfig(msfapi) %endif BuildRequires: pkgconfig(vconf) diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index 25df611..324b2bf 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -24,7 +24,7 @@ #include #ifdef TV_PRODUCT #ifdef TV_BT_MODE -#include +#include #endif #ifdef TV_MSF_WIFI_MODE #include -- 2.7.4 From 33255c363e850a3025e606bd024f1d6ddd55de48 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Wed, 7 Jun 2017 19:32:30 +0900 Subject: [PATCH 06/16] Remove to check processing state in result callback from engine Change-Id: I9f062c969facab7377859154113889b16328b849 Signed-off-by: Wonnam Jang --- server/vcd_server.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/server/vcd_server.c b/server/vcd_server.c index 23675a8..fdad45b 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -465,13 +465,6 @@ static void* __recorder_stop(void *data) static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int count, const char* all_result, const char* non_fixed_result, const char* nlu_result, const char* msg, void *user_data) { - if (VCD_STATE_PROCESSING != vcd_config_get_service_state()) { - if (VCD_RECOGNITION_MODE_RESTART_CONTINUOUSLY != vcd_client_get_recognition_mode()) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not 'Processing' and mode is not 'Restart continuously'"); - return; - } - } - vc_info_parser_unset_result(vcd_client_manager_get_exclusive()); vcd_client_manager_set_result_text(all_result); @@ -1804,6 +1797,8 @@ int vcd_server_mgr_do_action(int pid, int type, const char* action) if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to process do action : %d", ret); } else { + vcd_config_set_service_state(VCD_STATE_PROCESSING); + vcdc_send_service_state(VCD_STATE_PROCESSING); SLOG(LOG_DEBUG, TAG_VCD, "[Server SUCCESS] Process do action"); } -- 2.7.4 From c5636cd761cbddacb5c4a1c46f4ec340a278c0ec Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Wed, 21 Jun 2017 15:59:54 +0900 Subject: [PATCH 07/16] Fix timing issue to hide tooltip when voice touch is consumed Change-Id: I4c96ffae5320a793af876066262cc781a1b72884 Signed-off-by: Wonnam Jang --- client/vc_widget.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/vc_widget.c b/client/vc_widget.c index c671570..6dfb664 100644 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -1061,7 +1061,7 @@ static Eina_Bool __vc_widget_start_recording(void *data) } -static Eina_Bool __vc_widget_notify_tooltip(void *data) +static void __vc_widget_notify_tooltip(void *data) { bool show = (bool)data; @@ -1099,12 +1099,12 @@ static Eina_Bool __vc_widget_notify_tooltip(void *data) g_w_start_timer = ecore_timer_add(0, __vc_widget_start_recording, NULL); } - return EINA_FALSE; + return; } void __vc_widget_cb_show_tooltip(int pid, bool show) { - ecore_timer_add(0, __vc_widget_notify_tooltip, (void*)show); + ecore_main_loop_thread_safe_call_async(__vc_widget_notify_tooltip, (void*)show); } static Eina_Bool __vc_widget_notify_result(void *data) -- 2.7.4 From ad52a9427db528819c096faf7d247fbd04d79bc0 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Wed, 21 Jun 2017 20:12:11 +0900 Subject: [PATCH 08/16] Fix dangling pointer issue with command list Change-Id: I028c2f9972c587b2143d1dc0e225eb80dd1f5af5 Signed-off-by: Wonnam Jang --- common/vc_command.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/common/vc_command.c b/common/vc_command.c index 1478fcd..5ae5859 100644 --- a/common/vc_command.c +++ b/common/vc_command.c @@ -37,6 +37,8 @@ static int g_feature_enabled = -1; static int g_privilege_allowed = 1; /* Always True */ static cynara *p_cynara = NULL; +static GList *g_cmdlist_list = NULL; + // For getting timestamp using regular expression static regex_t reg[MAX_NUM_REGEX]; @@ -178,6 +180,8 @@ int vc_cmd_list_create(vc_cmd_list_h* vc_cmd_list) *vc_cmd_list = (vc_cmd_list_h)list; + g_cmdlist_list = g_list_append(g_cmdlist_list, list); + SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p)", *vc_cmd_list); return VC_ERROR_NONE; @@ -204,12 +208,34 @@ int vc_cmd_list_destroy(vc_cmd_list_h vc_cmd_list, bool release_command) SLOG(LOG_DEBUG, TAG_VCCMD, "[List] list(%p)", list); - if (NULL != list) { - free(list); - list = NULL; + GList *iter = NULL; + vc_cmd_list_s *data = NULL; + + /* if list have item */ + if (g_list_length(g_cmdlist_list) > 0) { + /* Get a first item */ + iter = g_list_first(g_cmdlist_list); + + while (NULL != iter) { + data = iter->data; + if (data && list == data) { + g_cmdlist_list = g_list_remove_link(g_cmdlist_list, iter); + + free(data); + data = NULL; + + SLOG(LOG_DEBUG, TAG_VCCMD, "Client destroy"); + g_list_free(iter); + + return VC_ERROR_NONE; + } + /* Next item */ + iter = g_list_next(iter); + } } + SLOG(LOG_ERROR, TAG_VCCMD, "Fail to destroy client : handle is not valid"); - return VC_ERROR_NONE; + return VC_ERROR_INVALID_PARAMETER; } int vc_cmd_list_get_count(vc_cmd_list_h vc_cmd_list, int* count) -- 2.7.4 From 66d9a872ca038f71a0855ae79c5cefd420a30411 Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Tue, 13 Jun 2017 10:33:52 +0900 Subject: [PATCH 09/16] Apply sound manager to fix recorder issue Change-Id: I0069a8b618551e98f805deecd5274ae768233991 --- client/vc_mgr.c | 3 - server/vcd_recorder.c | 212 +++++++++++++++++++++++++++++++++++++++++++------- server/vcd_server.c | 6 +- 3 files changed, 187 insertions(+), 34 deletions(-) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index b64bdaa..62c4333 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -1889,10 +1889,7 @@ int __vc_mgr_cb_set_volume(float volume) g_volume_db = g_prev_volume_db + (g_cur_volume_db - g_prev_volume_db) / 5; - SLOG(LOG_DEBUG, TAG_VCM, "Set volume (%f)(%f)", g_volume_db, g_cur_volume_db); - if (NULL != g_m_set_volume_timer) { - SLOG(LOG_DEBUG, TAG_VCM, "Connect Timer is deleted"); ecore_timer_del(g_m_set_volume_timer); } diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index 324b2bf..e315f78 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -22,6 +22,7 @@ #include #include #include +#include #ifdef TV_PRODUCT #ifdef TV_BT_MODE #include @@ -42,6 +43,8 @@ #define FRAME_LENGTH 160 #define BUFFER_LENGTH FRAME_LENGTH * 2 +#define FOCUS_SERVER_READY "/tmp/.focus_server_ready" + #define VCP_AUDIO_ID_NONE "VC_AUDIO_ID_NONE" /**< None audio id */ static vcd_recorder_state_e g_recorder_state = VCD_RECORDER_STATE_READY; @@ -52,13 +55,13 @@ static vcd_recorder_interrupt_cb g_interrupt_cb = NULL; static audio_in_h g_audio_h; -#if 0 +#if 1 static sound_stream_info_h g_stream_info_h; #endif static vcp_audio_type_e g_audio_type; -static unsigned int g_audio_rate; +static int g_audio_rate; static int g_audio_channel; @@ -91,7 +94,6 @@ static void __msf_wifi_audio_data_receive_cb(msf_wifi_voice_data_s *voice_data, if (0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_MSF, sizeof(VCP_AUDIO_ID_MSF))) { vcd_state_e state = vcd_config_get_service_state(); if (VCD_STATE_READY == state) { - vcd_engine_set_audio_type(VCP_AUDIO_ID_MSF); vcd_recorder_set(VCP_AUDIO_ID_MSF, VCP_AUDIO_TYPE_PCM_S16_LE, 16000, 1); } else { SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] current audio type is (%s)", g_current_audio_type); @@ -101,6 +103,7 @@ static void __msf_wifi_audio_data_receive_cb(msf_wifi_voice_data_s *voice_data, if (VCD_RECORDER_STATE_RECORDING != g_recorder_state) { SLOG(LOG_WARN, TAG_VCD, "[Recorder] Not start yet, but send audio data vi MSF"); + vcd_recorder_start(); } if (NULL != g_audio_cb) { @@ -154,7 +157,6 @@ static void _bt_hid_audio_data_receive_cb(bt_hid_voice_data_s *voice_data, void if (0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_BLUETOOTH, sizeof(VCP_AUDIO_ID_BLUETOOTH))) { vcd_state_e state = vcd_config_get_service_state(); if (VCD_STATE_READY == state) { - vcd_engine_set_audio_type(VCP_AUDIO_ID_BLUETOOTH); vcd_recorder_set(VCP_AUDIO_ID_BLUETOOTH, VCP_AUDIO_TYPE_PCM_S16_LE, 16000, 1); } else { SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] current audio type is (%s)", g_current_audio_type); @@ -164,6 +166,7 @@ static void _bt_hid_audio_data_receive_cb(bt_hid_voice_data_s *voice_data, void if (VCD_RECORDER_STATE_RECORDING != g_recorder_state) { SLOG(LOG_WARN, TAG_VCD, "[Recorder] Not start yet, but send audio data vi Bluetooth"); + vcd_recorder_start(); } if (NULL != g_audio_cb) { @@ -210,7 +213,7 @@ static void _bt_hid_audio_data_receive_cb(bt_hid_voice_data_s *voice_data, void #endif -#if 0 +#if 1 static const char* __get_focus_changed_reason_code(sound_stream_focus_change_reason_e reason) { switch (reason) { @@ -229,7 +232,8 @@ static const char* __get_focus_changed_reason_code(sound_stream_focus_change_rea } } -static void __recorder_focus_state_cb(sound_stream_info_h stream_info, sound_stream_focus_change_reason_e reason, const char *extra_info, void *user_data) +static void __recorder_focus_state_cb(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state, + sound_stream_focus_change_reason_e reason, int sound_behavior, const char *extra_info, void *user_data) { SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Focus state changed cb"); @@ -238,17 +242,9 @@ static void __recorder_focus_state_cb(sound_stream_info_h stream_info, sound_str return; } - int ret; - sound_stream_focus_state_e state_for_recording; - ret = sound_manager_get_focus_state(g_stream_info_h, NULL, &state_for_recording); - if (SOUND_MANAGER_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to get focus state"); - return; - } - - SLOG(LOG_WARN, TAG_VCD, "[Recorder] focus state chagned to (%d) with reason (%s)", (int)state_for_recording, __get_focus_changed_reason_code(reason)); + SLOG(LOG_WARN, TAG_VCD, "[Recorder] focus state chagned to (%d) with reason (%s)", (int)focus_state, __get_focus_changed_reason_code(reason)); - if (VCD_RECORDER_STATE_RECORDING == g_recorder_state && SOUND_STREAM_FOCUS_STATE_RELEASED == state_for_recording) { + if (VCD_RECORDER_STATE_RECORDING == g_recorder_state && SOUND_STREAM_FOCUS_STATE_RELEASED == focus_state) { SLOG(LOG_WARN, TAG_VCD, "[Recorder] Focus released as interrupt"); if (NULL != g_interrupt_cb) { g_interrupt_cb(); @@ -257,6 +253,46 @@ static void __recorder_focus_state_cb(sound_stream_info_h stream_info, sound_str } #endif +static int __apply_device_for_stream_routing() +{ + sound_device_list_h device_list = NULL; + sound_device_h device = NULL; + sound_device_type_e type; + sound_device_io_direction_e io_direction; + + if (0 != sound_manager_get_current_device_list(SOUND_DEVICE_IO_DIRECTION_IN_MASK, &device_list)) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to get current device list"); + return -1; + } + + int ret = 0; + while (0 == (ret = sound_manager_get_next_device(device_list, &device))) { + if (0 != sound_manager_get_device_type(device, &type)) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to get device tyep"); + continue; + } + if (0 != sound_manager_get_device_io_direction(device, &io_direction)) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to get device io direction"); + continue; + } + if (SOUND_DEVICE_USB_AUDIO == type && SOUND_DEVICE_IO_DIRECTION_IN == io_direction) { + if (0 != sound_manager_add_device_for_stream_routing(g_stream_info_h, device)) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to add device"); + continue; + } + if (0 != sound_manager_apply_stream_routing(g_stream_info_h)) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR} Fail to apply stream routing"); + continue; + } + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Apply device for stream routing"); + return 0; + } + } + + SLOG(LOG_WARN, TAG_VCD, "[Recorder] No device"); + return -1; +} + int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb interrupt_cb) { if (NULL == audio_cb || NULL == interrupt_cb) { @@ -264,6 +300,19 @@ int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb return VCD_ERROR_INVALID_PARAMETER; } + /* check focus server */ + int cnt = 0; + while (1) { + if (0 == access(FOCUS_SERVER_READY, F_OK)) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder SUCCESS] focus server is available"); + break; + } else { + if (0 == cnt++ % 10) + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] focus server is not available"); + usleep(50000); + } + } + int ret = 0; /* set init value */ @@ -278,6 +327,8 @@ int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb audio_channel_e audio_ch; audio_sample_type_e audio_type; + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] AUdio type(%d) rate(%d) channel(%d)", g_audio_type, g_audio_rate, g_audio_channel); + switch (g_audio_channel) { case 1: audio_ch = AUDIO_CHANNEL_MONO; break; case 2: audio_ch = AUDIO_CHANNEL_STEREO; break; @@ -305,9 +356,15 @@ int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb g_is_valid_audio_in = false; } -#if 0 - if (0 != sound_manager_create_stream_information(SOUND_STREAM_TYPE_VOICE_RECOGNITION, __recorder_focus_state_cb, NULL, &g_stream_info_h)) { +#if 1 + if (0 != sound_manager_create_stream_information_internal(SOUND_STREAM_TYPE_VOICE_RECOGNITION_SERVICE, __recorder_focus_state_cb, NULL, &g_stream_info_h)) { SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to create stream info"); + } else { + __apply_device_for_stream_routing(); + } + + if (0 != audio_in_set_sound_stream_info(g_audio_h, g_stream_info_h)) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to set stream info"); } #endif @@ -341,10 +398,15 @@ int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb } #endif /* Select default audio type */ - if (true == g_is_valid_bt_in) { - g_current_audio_type = strdup(VCP_AUDIO_ID_BLUETOOTH); - } else { + if (true == g_is_valid_audio_in) { g_current_audio_type = strdup(VCP_AUDIO_ID_NONE); + } else { + if (true == g_is_valid_bt_in) { + g_current_audio_type = strdup(VCP_AUDIO_ID_BLUETOOTH); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] No valid audio"); + return -1; + } } SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Audio type : %s", g_current_audio_type); @@ -408,9 +470,23 @@ int vcd_recorder_set(const char* audio_type, vcp_audio_type_e type, int rate, in } } + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] set audio type (%s)", audio_type); + vcd_engine_set_audio_type(audio_type); + if (VCD_RECORDER_STATE_READY != g_recorder_state) { - SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Recorder is NOT ready"); - return VCD_ERROR_INVALID_STATE; + if ((!strncmp(g_current_audio_type, VCP_AUDIO_ID_NONE, strlen(g_current_audio_type)) && + strncmp(audio_type, VCP_AUDIO_ID_BLUETOOTH, strlen(audio_type)) && + strncmp(audio_type, VCP_AUDIO_ID_MSF, strlen(audio_type))) || + (strncmp(g_current_audio_type, VCP_AUDIO_ID_BLUETOOTH, strlen(g_current_audio_type)) && + strncmp(g_current_audio_type, VCP_AUDIO_ID_MSF, strlen(g_current_audio_type)) && + strncmp(g_current_audio_type, VCP_AUDIO_ID_NONE, strlen(g_current_audio_type)) && + !strncmp(audio_type, VCP_AUDIO_ID_NONE, strlen(audio_type)))) { + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Skip stop recording while Recorder is NOT ready"); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Recorder is NOT ready"); + vcd_recorder_stop(); + //return VCD_ERROR_INVALID_STATE; + } } int ret = -1; @@ -441,6 +517,7 @@ int vcd_recorder_set(const char* audio_type, vcp_audio_type_e type, int rate, in } if (g_audio_type != type || g_audio_rate != rate || g_audio_channel != channel) { + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] New audio type(%d) rate(%d) channel(%d)", type, rate, channel); audio_in_destroy(g_audio_h); audio_channel_e audio_ch; @@ -471,6 +548,10 @@ int vcd_recorder_set(const char* audio_type, vcp_audio_type_e type, int rate, in return VCD_ERROR_OPERATION_FAILED; } + if (0 != audio_in_set_sound_stream_info(g_audio_h, g_stream_info_h)) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to set stream info"); + } + g_audio_type = type; g_audio_rate = rate; g_audio_channel = channel; @@ -591,6 +672,69 @@ Eina_Bool __read_normal_func(void *data) return EINA_TRUE; } +static void __check_audio_format() +{ + vcp_audio_type_e type; + int rate; + int channel; + + int ret = vcd_engine_get_audio_format(VCP_AUDIO_ID_NONE, &type, &rate, &channel); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio format : %d", ret); + return; + } + + if (false == g_is_valid_audio_in) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Audio-in is NOT valid"); + return; + } + + if (g_audio_type != type || g_audio_rate != rate || g_audio_channel != channel) { + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] New audio type(%d) rate(%d) channel(%d)", type, rate, channel); + audio_in_destroy(g_audio_h); + + audio_channel_e audio_ch; + audio_sample_type_e audio_type; + + switch (channel) { + case 1: audio_ch = AUDIO_CHANNEL_MONO; break; + case 2: audio_ch = AUDIO_CHANNEL_STEREO; break; + default: + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Input channel is not supported"); + return; + break; + } + + switch (type) { + case VCP_AUDIO_TYPE_PCM_S16_LE: audio_type = AUDIO_SAMPLE_TYPE_S16_LE; break; + case VCP_AUDIO_TYPE_PCM_U8: audio_type = AUDIO_SAMPLE_TYPE_U8; break; + default: + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Invalid Audio Type"); + return; + break; + } + + ret = audio_in_create(rate, audio_ch, audio_type, &g_audio_h); + if (AUDIO_IO_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to create audio handle : %d", ret); + g_is_valid_audio_in = false; + return; + } + + if (0 != audio_in_set_sound_stream_info(g_audio_h, g_stream_info_h)) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to set stream info"); + } + + g_audio_type = type; + g_audio_rate = rate; + g_audio_channel = channel; + } else { + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] audio type(%d) rate(%d) channel(%d)", g_audio_type, g_audio_rate, g_audio_channel); + } +} + + + int vcd_recorder_start() { int ret = -1; @@ -647,6 +791,8 @@ int vcd_recorder_start() SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] started = %d", started); if (false == started) { + /* check audio format */ + __check_audio_format(); #if 0 ret = sound_manager_acquire_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_RECORDING, NULL); if (SOUND_MANAGER_ERROR_NONE != ret) { @@ -726,6 +872,13 @@ int vcd_recorder_stop() break; } } + if (NULL != g_current_audio_type && + (!strncmp(g_current_audio_type, VCP_AUDIO_ID_BLUETOOTH, sizeof(VCP_AUDIO_ID_BLUETOOTH)) || + !strncmp(g_current_audio_type, VCP_AUDIO_ID_MSF, sizeof(VCP_AUDIO_ID_MSF)))) { + SLOG(LOG_DEBUG, TAG_VCD, "[DEBUG] Recorder reset to NONE"); + vcd_recorder_set(VCP_AUDIO_ID_NONE, g_audio_type, g_audio_rate, g_audio_channel); + } + if (false == stoped) { SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to stop bt audio"); return VCD_ERROR_OPERATION_FAILED; @@ -734,8 +887,16 @@ int vcd_recorder_stop() } else if (0 == strncmp(VCP_AUDIO_ID_MSF, g_current_audio_type, strlen(VCP_AUDIO_ID_MSF))) { #ifdef TV_MSF_WIFI_MODE UnRegisterMSFAudioCallback(); + if (NULL != g_current_audio_type && + (!strncmp(g_current_audio_type, VCP_AUDIO_ID_BLUETOOTH, sizeof(VCP_AUDIO_ID_BLUETOOTH)) || + !strncmp(g_current_audio_type, VCP_AUDIO_ID_MSF, sizeof(VCP_AUDIO_ID_MSF)))) { + SLOG(LOG_DEBUG, TAG_VCD, "[DEBUG] Recorder reset to NONE"); + vcd_recorder_set(VCP_AUDIO_ID_NONE, g_audio_type, g_audio_rate, g_audio_channel); + } stoped = true; #endif + } else { + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] current audio type is NONE"); } } @@ -754,11 +915,6 @@ int vcd_recorder_stop() #endif } - if (NULL != g_current_audio_type && 0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_NONE, sizeof(VCP_AUDIO_ID_NONE))) { - vcd_recorder_set(VCP_AUDIO_ID_NONE, VCP_AUDIO_TYPE_PCM_S16_LE, 16000, 1); - vcd_engine_set_audio_type(VCP_AUDIO_ID_NONE); - } - return 0; } diff --git a/server/vcd_server.c b/server/vcd_server.c index fdad45b..0b1ae73 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1516,7 +1516,7 @@ static int __start_internal_recognition() SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start engine"); -#if 0 +#if 1 /* 5. recorder start */ ret = vcd_recorder_start(); if (0 != ret) { @@ -1619,7 +1619,7 @@ int vcd_server_mgr_stop() return VCD_ERROR_OPERATION_FAILED; } -#if 0 +#if 1 /* 2. Stop recorder */ vcd_recorder_stop(); #endif @@ -1658,7 +1658,7 @@ int vcd_server_mgr_cancel() return VCD_ERROR_NONE; } -#if 0 +#if 1 /* 2. Stop recorder */ vcd_recorder_stop(); #endif -- 2.7.4 From f5bad5dfbdf2b672bdccb68500f90c8f9c2812a5 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Wed, 28 Jun 2017 16:59:41 +0900 Subject: [PATCH 10/16] Fix dlog format argument error Change-Id: I9cdb77a7a4faea05d6b6db6d690f14ad7c1adac5 Signed-off-by: Wonnam Jang --- common/vc_cmd_db.c | 2 +- common/vc_command.c | 2 +- common/vc_json_parser.c | 2 +- server/vcd_dbus_server.c | 2 +- server/vcd_recorder.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index 2e35e84..ca87d8b 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -759,7 +759,7 @@ static int __vc_db_get_result(char** result_text, int* event, char** msg, int pi if (-1 == pid) SLOG(LOG_DEBUG, vc_db_tag(), "[SQL] %s", sql); else if (NULL != appid) - SLOG(LOG_DEBUG, vc_db_tag(), "[SQL] SELECT * FROM vc_result WHERE appid = %d;", appid); + SLOG(LOG_DEBUG, vc_db_tag(), "[SQL] SELECT * FROM vc_result WHERE appid = %s;", appid); else SLOG(LOG_DEBUG, vc_db_tag(), "[SQL] SELECT * FROM vc_result WHERE pid = %d;", pid); diff --git a/common/vc_command.c b/common/vc_command.c index 5ae5859..1263d48 100644 --- a/common/vc_command.c +++ b/common/vc_command.c @@ -2314,7 +2314,7 @@ int vc_cmd_get_datetime(const char *text, time_t *result, char **remain) if (g_time_flag > 0 || g_date_flag > 0) { *result = mktime(&td); - SLOG(LOG_DEBUG, TAG_VCCMD, "Timestamp in the text = %d", *result); + SLOG(LOG_DEBUG, TAG_VCCMD, "Timestamp in the text = %ld", *result); SLOG(LOG_DEBUG, TAG_VCCMD, "%d-%d-%d (%s), %d:%d:%d", td.tm_year + 1900, td.tm_mon + 1, td.tm_mday, day_name[td.tm_wday], td.tm_hour, td.tm_min, td.tm_sec, td.tm_yday); diff --git a/common/vc_json_parser.c b/common/vc_json_parser.c index 8ab0e4f..3f6a487 100755 --- a/common/vc_json_parser.c +++ b/common/vc_json_parser.c @@ -388,7 +388,7 @@ int vc_json_set_commands_from_file(const char* file_path, vc_cmd_type_e type, ch parser = json_parser_new(); json_parser_load_from_file(parser, file_path, &err_msg); if (err_msg) { - SLOG(LOG_ERROR, vc_json_tag(), "[ERROR] Fail to load json file, file_path(%s), err_msg(%s)", file_path, err_msg); + SLOG(LOG_ERROR, vc_json_tag(), "[ERROR] Fail to load json file, file_path(%s), err_msg(%s)", file_path, err_msg->message); g_error_free(err_msg); g_object_unref(parser); return VC_ERROR_OPERATION_FAILED; diff --git a/server/vcd_dbus_server.c b/server/vcd_dbus_server.c index 169e3f4..45c92ec 100644 --- a/server/vcd_dbus_server.c +++ b/server/vcd_dbus_server.c @@ -33,7 +33,7 @@ int __dbus_error_return(DBusConnection* conn, DBusMessage* msg, int ret) DBUS_TYPE_INVALID); if (0 == ret) { - SLOG(LOG_DEBUG, TAG_VCD, "[OUT SUCCESS] Result(%d)"); + SLOG(LOG_DEBUG, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); } else { SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); } diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index 324b2bf..a04f281 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -119,7 +119,7 @@ static void __msf_wifi_audio_data_receive_cb(msf_wifi_voice_data_s *voice_data, } if (0 == g_buffer_count || 0 == g_buffer_count % 50) { - SLOG(LOG_WARN, TAG_VCD, "[Recorder][%d] Recording... : read_size(%d)", g_buffer_count, voice_data->length); + SLOG(LOG_WARN, TAG_VCD, "[Recorder][%d] Recording... : read_size(%ld)", g_buffer_count, voice_data->length); if (100000 == g_buffer_count) g_buffer_count = 0; -- 2.7.4 From 8c428b6c9aed1d0bd44e75f110f004d3274b9047 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Fri, 7 Jul 2017 10:26:05 +0900 Subject: [PATCH 11/16] Add to check null Change-Id: I96929a3ed6b8b1fdc2fb59eb9e84c457c7d8b355 Signed-off-by: Wonnam Jang --- client/vc_widget.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/client/vc_widget.c b/client/vc_widget.c index 6dfb664..b5cf497 100644 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -913,6 +913,10 @@ static Eina_Bool __vc_widget_notify_error(void *data) vc_error_cb callback = NULL; void* user_data; int reason; + if (NULL == vc_w) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } vc_widget_client_get_error_cb(vc_w, &callback, &user_data); vc_widget_client_get_error(vc_w, &reason); @@ -1226,6 +1230,10 @@ bool __vc_widget_cb_asr_result() static Eina_Bool __vc_widget_notify_state_changed(void *data) { vc_h vc_w = (vc_h)data; + if (NULL == vc_w) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); -- 2.7.4 From 595a0e3dcb14164fc5a6f65c52508185d8ff64c8 Mon Sep 17 00:00:00 2001 From: "sooyeon.kim" Date: Thu, 13 Jul 2017 15:34:27 +0900 Subject: [PATCH 12/16] Fix dlog level Change-Id: I6383742cd97713cfdfe87ff59ac549ed0e5f6102 Signed-off-by: sooyeon.kim --- client/vc_widget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/vc_widget.c b/client/vc_widget.c index b5cf497..201be60 100644 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -539,7 +539,7 @@ int vc_widget_get_state(vc_h vc_w, vc_state_e* state) vc_state_e temp; if (0 != vc_widget_client_get_state(vc_w, &temp)) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); + SLOG(LOG_DEBUG, TAG_VCW, "[ERROR] A handle is not available"); SLOG(LOG_DEBUG, TAG_VCW, "====="); SLOG(LOG_DEBUG, TAG_VCW, " "); return VC_ERROR_INVALID_STATE; -- 2.7.4 From 6a419e2de623e78283438fbadf4df1afd7adf386 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Tue, 11 Jul 2017 10:50:43 +0900 Subject: [PATCH 13/16] change ecore timer to async function Change-Id: Ie57bbd6c5ae9cdf28592ee5c5e11064ff6f2c1ac Signed-off-by: Wonnam Jang --- server/vcd_recorder.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index e2ac9c2..af4bb75 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -468,6 +468,9 @@ int vcd_recorder_set(const char* audio_type, vcp_audio_type_e type, int rate, in SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Current audio type is already set : %s", audio_type); return 0; } + } else { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Recorder is NOT created"); + return VCD_ERROR_INVALID_STATE; } SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] set audio type (%s)", audio_type); @@ -672,6 +675,13 @@ Eina_Bool __read_normal_func(void *data) return EINA_TRUE; } +static void __timer_read_normal_func(void *data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] before __read_normal_func"); + ecore_timer_add(0, __read_normal_func, NULL); + return; +} + static void __check_audio_format() { vcp_audio_type_e type; @@ -817,7 +827,7 @@ int vcd_recorder_start() } /* Add ecore timer to read audio data */ - ecore_timer_add(0, __read_normal_func, NULL); + ecore_main_loop_thread_safe_call_async(__timer_read_normal_func, NULL); SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Start audio in recorder"); } -- 2.7.4 From f6e03f4f94f0353e9ce35682bfe848b2fe18608d Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Mon, 17 Jul 2017 11:06:55 +0900 Subject: [PATCH 14/16] Update internal state when cancel is called in ready state Change-Id: I7f2816b1d931d6e31bd32759fa763670e6493530 Signed-off-by: Wonnam Jang --- client/vc_mgr.c | 12 ++++++------ server/vcd_server.c | 5 +++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 62c4333..fa15f7d 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -2511,12 +2511,6 @@ int __vc_mgr_cb_service_state(int state) vc_service_state_e before_state; vc_mgr_client_get_service_state(g_vc_m, &before_state); - if (current_state == before_state) { - SLOG(LOG_WARN, TAG_VCM, "Service State NOT changed : Before(%d) Current(%d)", - before_state, current_state); - return 0; - } - SLOG(LOG_DEBUG, TAG_VCM, "Service State changed : Before(%d) Current(%d)", before_state, current_state); @@ -2529,6 +2523,12 @@ int __vc_mgr_cb_service_state(int state) vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); } + if (current_state == before_state) { + SLOG(LOG_WARN, TAG_VCM, "Service State NOT changed : Before(%d) Current(%d)", + before_state, current_state); + return 0; + } + /* Save service state */ vc_mgr_client_set_service_state(g_vc_m, current_state); diff --git a/server/vcd_server.c b/server/vcd_server.c index 0b1ae73..a2aa150 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -558,6 +558,10 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int /* system > exclusive > foreground = widget > system_background > background */ int i = 0; int* filtered_id = (int*)calloc(count, sizeof(int)); + if (!filtered_id) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to allocate memory"); + return; + } int filtered_count = 0; int top_priority = VC_COMMAND_PRIORITY_BACKGROUND; for (i = 0; i < count; i++) { @@ -1655,6 +1659,7 @@ int vcd_server_mgr_cancel() if (VCD_STATE_READY == state) { SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is READY"); vcd_recorder_stop(); + vcdc_send_service_state(VCD_STATE_READY); return VCD_ERROR_NONE; } -- 2.7.4 From 0b9f70791b87f8ba9b9949b18efdcfca43e1ae81 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Mon, 24 Jul 2017 14:44:05 +0900 Subject: [PATCH 15/16] Fix wrong format for dlog Change-Id: I190fa88a76e8f8b212b96111ab74aaf4c0df0501 Signed-off-by: Wonnam Jang --- common/vc_cmd_db.c | 2 +- common/vc_command.c | 2 +- server/vcd_dbus_server.c | 6 +++--- server/vcd_recorder.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index ca87d8b..e68f92a 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -1259,7 +1259,7 @@ int vc_db_initialize(void) if (lstat(path, &stat) < 0) { char buf_err[256]; - SLOG(LOG_ERROR, vc_db_tag(), "%s", strerror_r(errno, buf_err, sizeof(buf_err))); + SLOG(LOG_ERROR, vc_db_tag(), "%d", strerror_r(errno, buf_err, sizeof(buf_err))); if (db_handle) db_util_close(db_handle); db_handle = NULL; diff --git a/common/vc_command.c b/common/vc_command.c index 1263d48..3efc055 100644 --- a/common/vc_command.c +++ b/common/vc_command.c @@ -2316,7 +2316,7 @@ int vc_cmd_get_datetime(const char *text, time_t *result, char **remain) SLOG(LOG_DEBUG, TAG_VCCMD, "Timestamp in the text = %ld", *result); SLOG(LOG_DEBUG, TAG_VCCMD, "%d-%d-%d (%s), %d:%d:%d", - td.tm_year + 1900, td.tm_mon + 1, td.tm_mday, day_name[td.tm_wday], td.tm_hour, td.tm_min, td.tm_sec, td.tm_yday); + td.tm_year + 1900, td.tm_mon + 1, td.tm_mday, day_name[td.tm_wday], td.tm_hour, td.tm_min, td.tm_sec); *remain = (char *)calloc(sizeof(char), (strlen(text) + 1 - g_data_eidx + g_data_sidx)); diff --git a/server/vcd_dbus_server.c b/server/vcd_dbus_server.c index 45c92ec..a83d053 100644 --- a/server/vcd_dbus_server.c +++ b/server/vcd_dbus_server.c @@ -124,7 +124,7 @@ int vcd_dbus_server_mgr_initialize(DBusConnection* conn, DBusMessage* msg) DBUS_TYPE_INVALID); if (0 == ret) { - SLOG(LOG_DEBUG, TAG_VCD, "[OUT SUCCESS] Result(%d)"); + SLOG(LOG_DEBUG, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); } else { SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); } @@ -1097,7 +1097,7 @@ int vcd_dbus_server_initialize(DBusConnection* conn, DBusMessage* msg) DBUS_TYPE_INVALID); if (0 == ret) { - SLOG(LOG_DEBUG, TAG_VCD, "[OUT SUCCESS] Result(%d)"); + SLOG(LOG_DEBUG, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); } else { SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); } @@ -1661,7 +1661,7 @@ int vcd_dbus_server_widget_initialize(DBusConnection* conn, DBusMessage* msg) DBUS_TYPE_INVALID); if (0 == ret) { - SLOG(LOG_DEBUG, TAG_VCD, "[OUT SUCCESS] Result(%d)"); + SLOG(LOG_DEBUG, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); } else { SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); } diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index af4bb75..f701b47 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -584,7 +584,7 @@ int vcd_recorder_get(char** audio_type) if (NULL != g_current_audio_type) { *audio_type = strdup(g_current_audio_type); } else { - SLOG(LOG_WARN, TAG_VCD, "[Recorder] Current audio type is NOT ready", audio_type); + SLOG(LOG_WARN, TAG_VCD, "[Recorder] Current audio type(%s) is NOT ready", audio_type); *audio_type = NULL; } @@ -675,7 +675,7 @@ Eina_Bool __read_normal_func(void *data) return EINA_TRUE; } -static void __timer_read_normal_func(void *data) +static void __timer_read_normal_func(void *data) { SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] before __read_normal_func"); ecore_timer_add(0, __read_normal_func, NULL); -- 2.7.4 From bc3afa0f427704d46f8758ff13361484d0c26aad Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Thu, 27 Jul 2017 15:28:10 +0900 Subject: [PATCH 16/16] Fix security issue Change-Id: I5c2742843ddfb86cb5c052e8abaeba9739319466 Signed-off-by: Suyeon Hwang --- common/vc_config_parser.c | 2 +- common/vc_info_parser.c | 2 +- server/vcd_recorder.c | 20 ++++++++++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/common/vc_config_parser.c b/common/vc_config_parser.c index eb9c867..f8ed365 100644 --- a/common/vc_config_parser.c +++ b/common/vc_config_parser.c @@ -54,7 +54,7 @@ static int __vc_config_parser_set_file_mode(const char* filename) return -1; } - if (0 > chmod(filename, 0666)) { + if (0 > chmod(filename, 0600)) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to change file mode"); return -1; } diff --git a/common/vc_info_parser.c b/common/vc_info_parser.c index 566e83b..8fda8ae 100644 --- a/common/vc_info_parser.c +++ b/common/vc_info_parser.c @@ -77,7 +77,7 @@ static int __vc_info_parser_set_file_mode(const char* filename) return -1; } - if (0 > chmod(filename, 0666)) { + if (0 > chmod(filename, 0600)) { SLOG(LOG_ERROR, vc_info_tag(), "[ERROR] Fail to change file mode"); return -1; } diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index f701b47..a1dfd2b 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -837,11 +837,27 @@ int vcd_recorder_start() char normal_file_name[128] = {'\0',}; g_count++; - snprintf(normal_file_name, sizeof(normal_file_name), "/tmp/vc_normal_%d_%d", getpid(), g_count); + while (1) { + snprintf(normal_file_name, sizeof(normal_file_name), "/tmp/vc_normal_%d_%d", getpid(), g_count); + ret = access(normal_file_name, 0); + + if (0 == ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] File is already exist"); + if (0 == remove(normal_file_name)) { + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Remove file"); + break; + } else { + g_count++; + } + } else { + break; + } + } + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] File normal name : %s", normal_file_name); /* open test file */ - g_normal_file = fopen(normal_file_name, "wb+"); + g_normal_file = fopen(normal_file_name, "wb+x"); if (!g_normal_file) { SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] File not found!"); } -- 2.7.4