From: hcj <1224667075@qq.com> Date: Fri, 1 Nov 2024 07:26:44 +0000 (+0800) Subject: 优化A2DP及HFP回连效果 X-Git-Tag: fd230_release_V1.3.102~147 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=a5971c20dd88e2803ac2c5c4a89f4e842902e484;p=mirrors%2FFD230.git 优化A2DP及HFP回连效果 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp index 97fdb7918..c30074a46 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp @@ -1462,11 +1462,23 @@ static void BtA2dpSnkConnectStateChangedCb(bd_addr_t *bd_addr, int conn_state) } else if (conn_state==PROFILE_STATE_CONNECTING || conn_state==PROFILE_STATE_CONNECTED) { +#ifdef BR_DISCONNECT + if(!cm_get_A2DP_switch()) + { + uapi_a2dp_snk_disconnect(); + return; + } + + if(cm_get_HFP_switch() && uapi_hfp_connect_state()==0) + { + uapi_hfp_connect(); + } +#endif SendMsgToUIService(BT_CONNECTED_TO_UI, 0, nullptr, 0); SendMsgToMsgCenterService(BT_CONNECTED_TO_MSGCENTER, 0, nullptr, 0); - if(pbap_pce_get_device_connect_state(bd_addr)==PROFILE_STATE_DISCONNECTING || - pbap_pce_get_device_connect_state(bd_addr)==PROFILE_STATE_DISCONNECTED) - uapi_pbap_cmd_start_client(); + // if(pbap_pce_get_device_connect_state(bd_addr)==PROFILE_STATE_DISCONNECTING || + // pbap_pce_get_device_connect_state(bd_addr)==PROFILE_STATE_DISCONNECTED) + // uapi_pbap_cmd_start_client(); // if(conn_state==PROFILE_STATE_CONNECTED) // { // if(pbap_pce_get_device_connect_state(bd_addr)==PROFILE_STATE_DISCONNECTED) @@ -1850,7 +1862,7 @@ int uapi_a2dp_snk_disconnect_() uapi_get_br_address(&bdaddr); int ret = a2dp_snk_disconnect(&bdaddr); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"state(int): %d\n", ret); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"state(int): %X\n", ret); return ret; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp index b1fbfccc5..bbaff85f7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp @@ -9,7 +9,7 @@ #include "ui_resource_string.h" #include "cmsis_os2.h" #include "graphic_service.h" - +#include "ConfigModelC.h" namespace OHOS { static BluetoothServiceOptionsView *g_pBluetoothServiceOptionsView{nullptr}; @@ -94,7 +94,7 @@ namespace OHOS static osTimerId_t MG_TEST_timer=NULL; static uint8_t button_state=0; static uint8_t count_num=0; - + static uint8_t connect_state=0; bool BluetoothServiceOptionsView::get_connectview_Visible(void) { return connectingScrollView->IsVisible(); @@ -102,36 +102,48 @@ namespace OHOS static void connectTimerCallBackProc(int data) { - bool connect_state=false; + count_num++; switch (button_state) { case BluetoothServiceOptionsView::CONNECT_HFP: if(uapi_hfp_connect_state()) { - //BluetoothServiceOptionsView::GetInstance()->show_connecting_view(false); - connect_state=true; + if(cm_get_A2DP_switch()&&uapi_a2dp_snk_get_device_connect_state()) + { + connect_state++; + } + else if(!cm_get_A2DP_switch()) + { + connect_state++; + } + + } break; case BluetoothServiceOptionsView::DISCONNECT_HFP: if(!uapi_hfp_connect_state()) { //BluetoothServiceOptionsView::GetInstance()->show_connecting_view(false); - connect_state=true; + + { + connect_state++; + } + } break; case BluetoothServiceOptionsView::CONNECT_A2DP: if(uapi_a2dp_snk_get_device_connect_state()) { //BluetoothServiceOptionsView::GetInstance()->show_connecting_view(false); - connect_state=true; + connect_state++; } break; case BluetoothServiceOptionsView::DISCONNECT_A2DP: if(!uapi_a2dp_snk_get_device_connect_state()) { //BluetoothServiceOptionsView::GetInstance()->show_connecting_view(false); - connect_state=true; + connect_state++; } break; @@ -139,7 +151,7 @@ namespace OHOS break; } - if(count_num==9 || connect_state) + if(count_num==9 || connect_state>=2) { if( BluetoothServiceOptionsView::GetInstance()) BluetoothServiceOptionsView::GetInstance()->show_connecting_view(false); @@ -191,6 +203,8 @@ namespace OHOS } MG_TEST_timer = osTimerNew((osTimerFunc_t)connectTimerCallBack, osTimerPeriodic, NULL, NULL); tick =500; + connect_state=0; + retTimer = osTimerStart(MG_TEST_timer, tick); if (retTimer != osOK && MG_TEST_timer != NULL) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"StartCallTimer osTimerStart failed, ret = %lx!!", retTimer); diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp index 12cdc63ae..6d0cbaf55 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp @@ -18,6 +18,7 @@ #include "BluetoothModel.h" #include "custom_runtime.h" #include "ConfigModelC.h" +#include "PhoneService.h" namespace OHOS { // 当前Presenter属性实例化的内存指针 @@ -126,7 +127,7 @@ namespace OHOS uapi_get_br_address(&bdaddr); if( uapi_dev_runtime_get_bt_powerstat() && (cm_get_HFP_switch()||cm_get_A2DP_switch())) { - if (false==bt_is_acl_connected(&bdaddr) && !(bdaddr.addr[0]==0 && bdaddr.addr[1]==0 && bdaddr.addr[2]==0 && bdaddr.addr[3]==0 + if ( cm_get_HFP_switch()&& cm_get_A2DP_switch() && false==bt_is_acl_connected(&bdaddr) && !(bdaddr.addr[0]==0 && bdaddr.addr[1]==0 && bdaddr.addr[2]==0 && bdaddr.addr[3]==0 && bdaddr.addr[4]==0 && bdaddr.addr[5]==0)) { int ret = gap_reconnect_media_device(&bdaddr); @@ -135,8 +136,15 @@ namespace OHOS else { - if(cm_get_A2DP_switch() || cm_get_HFP_switch()) - uapi_a2dp_snk_connect(); + if(cm_get_A2DP_switch()) + { + uapi_a2dp_snk_connect(); + } + if(cm_get_HFP_switch()) + { + uapi_hfp_connect(); + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_a2dp_snk_connect!!! \r\n"); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/phoneservice/include/PhoneService.h b/code/sdk/application/wearable/fd230app/nativeui/phoneservice/include/PhoneService.h index 4cd62dbfb..c4c7919f1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phoneservice/include/PhoneService.h +++ b/code/sdk/application/wearable/fd230app/nativeui/phoneservice/include/PhoneService.h @@ -12,6 +12,8 @@ #include "ohos_types.h" #include "PhoneAudio.h" +#define BR_DISCONNECT + #ifdef __cplusplus extern "C" { #endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp b/code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp index 1c9210e0a..1760f8829 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp @@ -37,7 +37,7 @@ #include "custom_runtime.h" #include "vibrator_service.h" #include "gfx_utils/mem_api.h" -#include "ConfigModel.h" +#include "ConfigModelC.h" #include "cat1_ctl.h" #ifdef __cplusplus extern "C" { @@ -649,10 +649,30 @@ static void ConnStateChanged(const bd_addr_t *bdAddr, profile_connect_state_t st switch (state) { case PROFILE_STATE_CONNECTING: // 蓝牙正在连接 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ConnStateChanged] BT connecting"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[ConnStateChanged] BT connecting"); + #ifdef BR_DISCONNECT + if(!cm_get_HFP_switch()) + { + uapi_hfp_disconnect(); + return; + } + #endif break; case PROFILE_STATE_CONNECTED: // 蓝牙连接成功 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ConnStateChanged] BT connected"); + #ifdef BR_DISCONNECT + if(!cm_get_HFP_switch()) + { + uapi_hfp_disconnect(); + return; + } + + if(cm_get_A2DP_switch() && OHOS::uapi_a2dp_snk_get_device_connect_state()==0) + { + OHOS::uapi_a2dp_snk_connect(); + } + + #endif BtConnectedPro(bdAddr); SendMsgToUIService(BT_CONNECTED_TO_UI, 0, nullptr, 0); uapi_pbap_cmd_start_client(); @@ -2166,6 +2186,8 @@ int TransCallToMobilePhone(void) } } +#include "los_base.h" + int uapi_hfp_disconnect_(void) { int ret; @@ -2181,6 +2203,10 @@ int uapi_hfp_disconnect_(void) int uapi_hfp_connect_(void) { + // if(uapi_hfp_connect_state()==1) + // { + // return; + // } int ret; bd_addr_t bdaddr={0}; OHOS:: uapi_get_br_address(&bdaddr); @@ -2197,10 +2223,28 @@ int uapi_hfp_connect_(void) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[bt_is_acl_connected is true"); ret = hfp_hf_connect(&bdaddr); - if(ret!=ERRCODE_SUCC) + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[uapi_hfp_connect] ret:%X", ret); + if(ret==0x8000600B) { - ret=gap_reconnect_media_device(&bdaddr); + gap_disconnect_remote_device(&bdaddr); + sleep(1); + //if(ret!=ERRCODE_SUCC) + { + ret=gap_reconnect_media_device(&bdaddr); + } + + + } + else + { + if(ret!=ERRCODE_SUCC) + { + ret=gap_reconnect_media_device(&bdaddr); + } } + + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[uapi_hfp_connect] ret:%X", ret); } diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c index e50e05978..c3573a8c2 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -55,6 +55,9 @@ extern "C" { #define MAX_BLE_EVENT_DIAL_NUM (10) //表盘最大数量 +#include "upg_common_porting.h" + + uint32_t packdataLen = 0; uint32_t totalDataLen = 0; uint8_t totalpack = 0; @@ -108,10 +111,10 @@ static uint32_t timer_flie_flag=0; ble_read_data* ble_read_timer_p=NULL; #ifdef SINGLE_USER_PARTITION -#define UP_DATE_FWPKG_PATH "/user/update/update.fwpkg" +#define UP_DATE_FWPKG_PATH UPG_FILE_NAME #else -#define UP_DATE_FWPKG_PATH "/update/update.fwpkg" +#define UP_DATE_FWPKG_PATH UPG_FILE_NAME #endif @@ -2885,18 +2888,19 @@ uint8_t parse_jsonCheck_weather(uint8_t *buf,uint8_t *check)//json 格式解析 uapi_get_br_address(&bdaddr); if( uapi_dev_runtime_get_bt_powerstat() && (cm_get_HFP_switch()||cm_get_A2DP_switch())) { - if (false==bt_is_acl_connected(&bdaddr) && !(bdaddr.addr[0]==0 && bdaddr.addr[1]==0 && bdaddr.addr[2]==0 && bdaddr.addr[3]==0 + + if(cm_get_A2DP_switch() && cm_get_A2DP_switch() && false==bt_is_acl_connected(&bdaddr) && !(bdaddr.addr[0]==0 && bdaddr.addr[1]==0 && bdaddr.addr[2]==0 && bdaddr.addr[3]==0 && bdaddr.addr[4]==0 && bdaddr.addr[5]==0)) { - int ret = gap_reconnect_media_device(&bdaddr); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " gap_reconnect_media_device ret = %u %02x %02x %02x ", ret,bdaddr.addr[5],bdaddr.addr[4],bdaddr.addr[3]); + gap_reconnect_media_device(&bdaddr); } - else + else if(cm_get_A2DP_switch()) { - - if(cm_get_A2DP_switch() || cm_get_HFP_switch()) uapi_a2dp_snk_connect(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_a2dp_snk_connect!!! \r\n"); + } + else if(cm_get_HFP_switch()) + { + uapi_hfp_connect(); } } diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c index 41b5a8266..1b9f4b36f 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c @@ -39,6 +39,7 @@ extern "C" { #include "custom_runtime.h" #include "custom_utils.h" #include "bletest.h" +#include "ConfigModelC.h" #ifdef SUPPORT_AT_CYWEE #include "cywee_ble_Service.h" #endif @@ -575,8 +576,20 @@ void svr_pair_result_cbt_cb(uint16_t conn_id, const bd_addr_t *addr, errcode_t s if(get_ble_pair()&&( cm_get_A2DP_switch() || cm_get_HFP_switch())) { - int ret=gap_reconnect_media_device(addr); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "gap_reconnect_media_device!!! %X\r\n",ret); + if(cm_get_A2DP_switch() && cm_get_A2DP_switch()) + { + int ret=gap_reconnect_media_device(addr); + } + else if(cm_get_A2DP_switch()) + { + uapi_a2dp_snk_connect(); + } + else if(cm_get_HFP_switch()) + { + uapi_hfp_connect(); + } + + } else { @@ -603,7 +616,6 @@ void svr_pair_result_cbt_cb(uint16_t conn_id, const bd_addr_t *addr, errcode_t s } } hand_watch_first_time_Paired(); - svr_ble_adv_stop(); } } @@ -1605,6 +1617,9 @@ static void svr_ble_mtu_exchange(uint8_t server_id, uint16_t conn_id, uint16_t m /******************* gap_ble ************************************/ void svr_gap_ble_auth_complete_callback(uint16_t conn_id, const bd_addr_t *addr, errcode_t status,ble_auth_info_evt_t* evt) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sendParieSuccess"); + + sendParieSuccess(1,addr); uapi_set_br_address(addr); }