From: 胡传军 <1224667075@qq.com> Date: Fri, 16 Aug 2024 01:35:56 +0000 (+0000) Subject: Merge #700 into sdk602patch0626 from refs/changes/700/head X-Git-Tag: release_V1.2.70_20241020_135402~658^2~2 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=9fea2b3ac56d5a599b5bfda6a462295d591b41c6;p=mirrors%2FFD230.git Merge #700 into sdk602patch0626 from refs/changes/700/head Code review from 胡传军 * refs/changes/700/head: (3 commits squashed) - 修改br连接接口 改用消息机制 增加回连判断 实际实现传统蓝牙开关关闭则br连接不上(有BUG) - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into 0626 - 增加连接中 UI 及部分蓝牙问题修正 Signed-off-by: aliyun8003852482 <1224667075@qq.com> Reviewed-by: snickersun@163.com Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/700 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceConnectingView.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceConnectingView.h index ec7cdbe14..28eb6ac65 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceConnectingView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceConnectingView.h @@ -56,7 +56,7 @@ namespace OHOS ~AiVoiceConnectingView(); static AiVoiceConnectingView *GetInstance(void); UIScrollView *CreateAiVoiceConnectingView(void); - + UIScrollView *CreateAiVoiceConnectingView(uint8_t); private: const char **CreateImagePathsArray(const char *basePath, const int numImages, const char *fileExtension = "bin"); void FreeImagePathsArray(const char **imagePaths, const int numImages); @@ -67,6 +67,7 @@ namespace OHOS bool CreateAiVoiceConnectingViewButton(void); bool CreateAivoiceConnectingImageAnimator(void); bool CreateAiVoiceConnectingScrollView(void); + bool CreateAiVoiceConnectingScrollView(uint8_t); void ClearAll(void); UIScrollView *scrollView{nullptr}; UILabelExt *title{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp index 790abdcea..29514a936 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp @@ -16,7 +16,7 @@ namespace OHOS static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_Y = 153; static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_W = 100; static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_H = 120; - static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_DELAY = 200; // 图片更新间隔 + static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_DELAY = 50; // 图片更新间隔 static constexpr const char *AIVoiceListeningImagePaths = "/user/res/connect/"; static AiVoiceConnectingView *g_pAiVoiceConnecting{nullptr}; @@ -283,6 +283,23 @@ namespace OHOS return true; } + bool AiVoiceConnectingView::CreateAiVoiceConnectingScrollView(uint8_t type) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingScrollView"); + scrollView = new UIScrollView(); + if (scrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::scrollView new fail!"); + return false; + } + scrollView->SetPosition(0, 0, 466, 466); + scrollView->SetTouchable(true); + scrollView->SetDraggable(true); + + return true; + } + + UIScrollView *AiVoiceConnectingView::CreateAiVoiceConnectingView(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingView"); @@ -299,4 +316,16 @@ namespace OHOS return scrollView; } + UIScrollView *AiVoiceConnectingView::CreateAiVoiceConnectingView(uint8_t type) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingView"); + if (!CreateAiVoiceConnectingScrollView(type) || !CreateAivoiceConnectingImageAnimator()|| !CreateAiVoiceConnectingViewLabel() ) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingView fail!!"); + return nullptr; + } + scrollView->Add(connectingAnimatorView); + return scrollView; + } + } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModelC.h b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModelC.h new file mode 100644 index 000000000..785a37ad0 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModelC.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: BluetoothModel view + * Author: + * Create: 2021-10-13 + */ + +#ifndef C_BLUETOOTH_MODEL_H_ +#define C_BLUETOOTH_MODEL_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + +int uapi_a2dp_snk_connect_(void); +int uapi_a2dp_snk_disconnect_(void); +//int uapi_disconnect_remote_device_(void); + +int uapi_reconnect_(void); + + +#ifdef __cplusplus +} +#endif + + +#endif 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 325e7484b..586115c84 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp @@ -6,6 +6,8 @@ */ #include #include "BluetoothModel.h" +#include "BluetoothModelC.h" + #include "BluetoothWrapper.h" #include "BluetoothPresenter.h" #include "ConnectPhonePresenter.h" @@ -23,7 +25,8 @@ #include "bts_spp.h" #include "osal_task.h" #include "bts_pbap.h" - +#include "ConfigModelC.h" +#include "custom_utils.h" #ifdef SUPPORT_ALIPAY_SEC #include "alipay_feature.h" #endif @@ -44,6 +47,8 @@ #include "BluetoothWrapper.h" #endif #include "Bluetooyhpabpserver.h" +#include "bletest.h" +#include "ConfigModelC.h" namespace OHOS { #define BT_SPP_TASK_STACK_SIZE 2048 @@ -241,7 +246,7 @@ void bluetooth_close_all(void) /**TODO: 断开BR链接**/ bd_addr_t bdaddr={0}; - get_phone_addr(&bdaddr); + uapi_get_br_address(&bdaddr); if (bt_is_acl_connected(&bdaddr)) { ret = gap_disconnect_remote_device(&bdaddr); @@ -754,14 +759,25 @@ void BtGapPairStatusChangedCallback(const bd_addr_t *bdAddr, int status) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BtGapPairStatusChangedCallback addr: ****%02x%02x%02x%02x status: %d\n", bdAddr->addr[3], bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0], status); /* addr下标 0 1 2 3 */ memcpy(&BtGapPair_bdAddr,bdAddr,sizeof(bd_addr_t)); - uapi_a2dp_snk_connect(); + // if(status == GAP_PAIR_PAIRED) + // { + + + //} //uapi_a2dp_snk_connect(); //a2dp_snk_connect(bdAddr); - + if(cm_custom_ble_service_on_flag() && !get_ble_pair()) + { + if(cm_get_A2DP_switch() || cm_get_HFP_switch()) + uapi_a2dp_snk_connect(); + //uapi_reconnect(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_a2dp_snk_connect"); + } if (status == GAP_PAIR_PAIRED) { if (ConnectPhonePresenter::GetInstance() != nullptr) { NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); } + } } @@ -994,6 +1010,11 @@ void GapAclStateChangedCallback(const bd_addr_t *bdAddr, gap_acl_state_t state, WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "addr: %02x%02x%02x%02x%02x%02x", bdAddr->addr[5], bdAddr->addr[4], bdAddr->addr[3], /* mac下标 0 1 2 3 4 5 */ bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0]); /* mac下标 0 1 2 3 4 5 */ + //效果不好 + if(!cm_custom_ble_service_on_flag()) + { + gap_disconnect_remote_device(bdAddr); + } //ALC_State_flag=state; @@ -1668,6 +1689,7 @@ int uapi_a2dp_snk_get_device_connect_state() void uapi_get_br_address(bd_addr_t *bdaddr) { + if(BtGapPair_bdAddr.addr[0]==0 && BtGapPair_bdAddr.addr[1]==0 && BtGapPair_bdAddr.addr[2]==0 && BtGapPair_bdAddr.addr[3]==0 ) get_phone_addr(bdaddr); @@ -1675,7 +1697,17 @@ void uapi_get_br_address(bd_addr_t *bdaddr) memcpy(bdaddr,&BtGapPair_bdAddr,sizeof(bd_addr_t)); } +static uint8_t br_cmd=0; int uapi_a2dp_snk_connect() +{ + br_cmd=BR_A2DP_CONNECT; + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_BR_CONNECT,&br_cmd,sizeof(br_cmd)); + return 0; + +} + + +int uapi_a2dp_snk_connect_() { bd_addr_t bdaddr={0}; @@ -1690,6 +1722,14 @@ int uapi_a2dp_snk_connect() } int uapi_a2dp_snk_disconnect() +{ + br_cmd=BR_A2DP_DISCONNECT; + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_BR_CONNECT,&br_cmd,sizeof(br_cmd)); + return 0; +} + + +int uapi_a2dp_snk_disconnect_() { bd_addr_t bdaddr={0}; @@ -1700,6 +1740,13 @@ int uapi_a2dp_snk_disconnect() return ret; } +// int uapi_disconnect_remote_device_() +// { +// do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_BR_CONNECT,&br_cmd,sizeof(br_cmd)); +// return 0; +// } + + int uapi_disconnect_remote_device() { bd_addr_t bdaddr={0}; @@ -1740,6 +1787,15 @@ int uapi_set_acl_connect_A2DP() } +int uapi_reconnect_() +{ + + br_cmd=BR_RECONNECT; + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_BR_CONNECT,&br_cmd,sizeof(br_cmd)); + return 0; +} + + int uapi_reconnect(void) { bd_addr_t bdaddr={0}; @@ -1750,6 +1806,8 @@ int uapi_reconnect(void) return 0; } + + // /////////////////////////////////////////HFP hf端 代码/////////////////////////////////////////////////// // int uapi_HFP_hf_connect() diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/BluetoothServiceOptionsView.h b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/BluetoothServiceOptionsView.h index eb20dde57..6b6db056d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/BluetoothServiceOptionsView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/BluetoothServiceOptionsView.h @@ -17,6 +17,7 @@ #include "components/ui_button.h" #include "components/ui_image_view.h" #include "components/ui_toggle_button.h" +#include "aivoice/include/AiVoiceConnectingView.h" namespace OHOS { // 返回setting视图界面 @@ -36,6 +37,15 @@ namespace OHOS uint16_t textId; uint8_t lineBreakMode; // 断行模式。 }; + + typedef enum + { + CONNECT_HFP = 0, + DISCONNECT_HFP, + CONNECT_A2DP, + DISCONNECT_A2DP, + } BluetoothServiceOptionsView_state; + BluetoothServiceOptionsView(); virtual ~BluetoothServiceOptionsView(); static BluetoothServiceOptionsView *GetInstance(void); @@ -43,7 +53,10 @@ namespace OHOS void ClearAll(void); UIToggleButton *GetHFP_ToggleButton(void); UIToggleButton *GetA2DP_ToggleButton(void); - + void show_connecting_view(bool data); + void Button_UPdata(void); + bool init_connect_timer(uint8_t type); + bool get_connectview_Visible(void); public: virtual void OnStart() override; virtual void OnSetUpView() override; @@ -64,6 +77,9 @@ namespace OHOS UIImageView *A2DP_Image{nullptr}; UIToggleButton *HFP_ToggleButton{nullptr}; // HFP UIToggleButton *A2DP_ToggleButton{nullptr}; // A2DP + UIScrollView * connectingScrollView{nullptr}; + AiVoiceConnectingView* p_AiVoiceConnectingView{nullptr}; + bool initViewStatus{false}; }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp index 5fb38d73b..189443280 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp @@ -78,31 +78,36 @@ namespace OHOS UIToggleButton *toggleButton = dynamic_cast(&view); if (toggleButton != nullptr) { + classicBlueToothView->show_connecting_view(true); if (toggleButton->GetState() == true) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s is enable!", it->second.c_str()); + //WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s is enable!", it->second.c_str()); if (it->second == "HFP") { ConfigModel::GetInstance()->SetHFPState(true); //enable_hfp_service(true); uapi_hfp_connect(); + classicBlueToothView->init_connect_timer(BluetoothServiceOptionsView::CONNECT_HFP); + } else if (it->second == "A2DP") { ConfigModel::GetInstance()->SetA2DPState(true); uapi_a2dp_snk_connect(); + classicBlueToothView->init_connect_timer(BluetoothServiceOptionsView::CONNECT_A2DP); //enable_a2dp_service(true); } } else { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s is disable!", it->second.c_str()); + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s is disable!", it->second.c_str()); if (it->second == "HFP") { ConfigModel::GetInstance()->SetHFPState(false); //enable_hfp_service(false); uapi_hfp_disconnect(); + classicBlueToothView->init_connect_timer(BluetoothServiceOptionsView::DISCONNECT_HFP); // errcode_t ret = gap_ble_set_ctkd_enable(false); // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "gap_ble_set_ctkd_enable ret = %u", ret); } @@ -111,8 +116,9 @@ namespace OHOS ConfigModel::GetInstance()->SetA2DPState(false); uapi_a2dp_snk_disconnect(); + classicBlueToothView->init_connect_timer(BluetoothServiceOptionsView::DISCONNECT_HFP); // uapi_hfp_disconnect(); - // uapi_disconnect_remote_device(); + //uapi_disconnect_remote_device(); // errcode_t ret = gap_ble_set_ctkd_enable(false); // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "gap_ble_set_ctkd_enable ret = %u", ret); //bluetooth_set_auto_reconnect(1); @@ -138,6 +144,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsPresenter::OnDragEnd"); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { + if(! BluetoothServiceOptionsView::GetInstance()->get_connectview_Visible()) NativeAbility::GetInstance().Back(); } @@ -152,6 +159,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { + if(! BluetoothServiceOptionsView::GetInstance()->get_connectview_Visible()) NativeAbility::GetInstance().Back(); } return true; 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 7461ab113..b3570cb0b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp @@ -7,6 +7,8 @@ #include "phoneservice/include/PhoneService.h" #include "BluetoothModel.h" #include "ui_resource_string.h" +#include "cmsis_os2.h" + namespace OHOS { static BluetoothServiceOptionsView *g_pBluetoothServiceOptionsView{nullptr}; @@ -72,12 +74,128 @@ namespace OHOS delete A2DP_ToggleButton; A2DP_ToggleButton = nullptr; } + if(p_AiVoiceConnectingView) + { + delete p_AiVoiceConnectingView; + p_AiVoiceConnectingView=nullptr; + } + if(connectingScrollView) + { + delete connectingScrollView; + connectingScrollView = nullptr; + } delete BlueToothScrollView; BlueToothScrollView = nullptr; } } } + static osTimerId_t MG_TEST_timer=NULL; + static uint8_t button_state=0; + static uint8_t count_num=0; + + bool BluetoothServiceOptionsView::get_connectview_Visible(void) + { + return connectingScrollView->IsVisible(); + } + + void connectTimerCallBack(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; + } + break; + case BluetoothServiceOptionsView::DISCONNECT_HFP: + if(!uapi_hfp_connect_state()) + { + BluetoothServiceOptionsView::GetInstance()->show_connecting_view(false); + connect_state=true; + } + break; + case BluetoothServiceOptionsView::CONNECT_A2DP: + if(uapi_a2dp_snk_get_device_connect_state()) + { + BluetoothServiceOptionsView::GetInstance()->show_connecting_view(false); + connect_state=true; + } + break; + case BluetoothServiceOptionsView::DISCONNECT_A2DP: + if(!uapi_a2dp_snk_get_device_connect_state()) + { + BluetoothServiceOptionsView::GetInstance()->show_connecting_view(false); + connect_state=true; + } + break; + + default: + break; + + } + if(count_num==3 || connect_state) + { + if( BluetoothServiceOptionsView::GetInstance()) + BluetoothServiceOptionsView::GetInstance()->show_connecting_view(false); + osTimerStop(MG_TEST_timer); + osTimerDelete(MG_TEST_timer); + MG_TEST_timer = NULL; + } + else if(count_num==2) + { + //仅尝试重连一次 + switch (button_state) + { + case BluetoothServiceOptionsView::CONNECT_HFP: + //uapi_hfp_connect(); + break; + case BluetoothServiceOptionsView::DISCONNECT_HFP: + //uapi_hfp_disconnect(); + break; + case BluetoothServiceOptionsView::CONNECT_A2DP: + // uapi_a2dp_snk_connect(); + break; + case BluetoothServiceOptionsView::DISCONNECT_A2DP: + //uapi_a2dp_snk_disconnect(); + break; + default: + break; + } + } + } + + bool BluetoothServiceOptionsView::init_connect_timer(uint8_t type) + { + uint32_t tick; + osStatus_t retTimer; + count_num=0; + button_state=type; + + if(MG_TEST_timer) + { + osTimerStop(MG_TEST_timer); + osTimerDelete(MG_TEST_timer); + MG_TEST_timer = NULL; + + } + MG_TEST_timer = osTimerNew((osTimerFunc_t)connectTimerCallBack, osTimerPeriodic, NULL, NULL); + tick =1500; + 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); + osTimerDelete(MG_TEST_timer); + MG_TEST_timer = NULL; + return false; + } + return true; + } + + bool BluetoothServiceOptionsView::SetUpBlueToothScrollView(void) { BlueToothScrollView = new UIScrollView(); @@ -262,6 +380,7 @@ namespace OHOS { BluetoothServiceOptionsViewInit(); initViewStatus = true; + } // 增加按键监听 @@ -269,6 +388,25 @@ namespace OHOS RootView::GetInstance()->SetOnKeyActListener(keyactListener); } + void BluetoothServiceOptionsView::show_connecting_view(bool data) + { + + connectingScrollView->SetVisible(data); + if(data==false) + { + A2DP_ToggleButton->SetState(uapi_a2dp_snk_get_device_connect_state()); + HFP_ToggleButton->SetState(uapi_hfp_connect_state()); // ConfigModel::GetInstance()->GetHFPState()); + } + } + + void BluetoothServiceOptionsView::Button_UPdata(void) + { + + A2DP_ToggleButton->SetState(uapi_a2dp_snk_get_device_connect_state()); + HFP_ToggleButton->SetState(uapi_hfp_connect_state()); // ConfigModel::GetInstance()->GetHFPState()); + + } + void BluetoothServiceOptionsView::OnSetUpView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::OnSetUpView"); @@ -280,6 +418,13 @@ namespace OHOS BlueToothScrollView->Add(A2DP_Label); BlueToothScrollView->Add(HFP_ToggleButton); BlueToothScrollView->Add(A2DP_ToggleButton); + p_AiVoiceConnectingView = new AiVoiceConnectingView(); + + connectingScrollView= p_AiVoiceConnectingView->CreateAiVoiceConnectingView(1); + connectingScrollView->SetVisible(false); + connectingScrollView->SetDraggable(false); + BlueToothScrollView->Add(connectingScrollView); + RootView::GetInstance()->Add(BlueToothScrollView); Draw(); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/phoneservice/include/PhoneServiceC.h b/code/sdk/application/wearable/fd230app/nativeui/phoneservice/include/PhoneServiceC.h new file mode 100644 index 000000000..458fbb477 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/phoneservice/include/PhoneServiceC.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: PhoneService + * Create: 2021-09-22 + */ + +#ifndef PHONE_SERVICE_H +#define PHONE_SERVICE_H + + +#ifdef __cplusplus +extern "C" { +#endif + +int uapi_hfp_disconnect_(void); + +int uapi_hfp_connect_(void); + + +#ifdef __cplusplus +} +#endif + +#endif // PHONE_SERVICE_H 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 b89b2c6bb..584f81954 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp @@ -5,6 +5,8 @@ */ #include "PhoneService.h" +#include "PhoneServiceC.h" + #include "PhoneAudio.h" #include "securec.h" #include @@ -28,6 +30,7 @@ #include "BluetoothModel.h" #include "notification_manager.h" #include "CallerLogModel.h" +#include "custom_utils.h" #ifdef __cplusplus extern "C" { #endif @@ -599,6 +602,8 @@ static void ConnStateChanged(const bd_addr_t *bdAddr, profile_connect_state_t st case PROFILE_STATE_CONNECTED: // 蓝牙连接成功 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ConnStateChanged] BT connected"); BtConnectedPro(bdAddr); + SendMsgToUIService(BT_CONNECTED_TO_UI, 0, nullptr, 0); + //SendMsgToMsgCenterService(BT_CONNECTED_TO_MSGCENTER, 0, nullptr, 0); break; case PROFILE_STATE_DISCONNECTING: // 蓝牙连接断连 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ConnStateChanged] BT disconnecting"); @@ -608,7 +613,8 @@ static void ConnStateChanged(const bd_addr_t *bdAddr, profile_connect_state_t st BtDisconnectedPro(); if(0==OHOS::uapi_a2dp_snk_get_device_connect_state() && 0==uapi_hfp_connect_state()) { - // remove by merge patch + SendMsgToUIService(BT_DISCONNECTED_TO_UI, 0, nullptr, 0); + //SendMsgToMsgCenterService(BT_DISCONNECTED_TO_MSGCENTER, 0, nullptr, 0); } break; @@ -1888,11 +1894,11 @@ int TransCallToMobilePhone(void) } } -int uapi_hfp_disconnect(void) +int uapi_hfp_disconnect_(void) { int ret; bd_addr_t bdaddr={0}; - get_phone_addr(&bdaddr); + OHOS:: uapi_get_br_address(&bdaddr); ret = hfp_hf_disconnect(&bdaddr); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "addr: ****%02x %02x %02x %02x g_bdAddr.type: %x\n", bdaddr.addr[3], bdaddr.addr[2], bdaddr.addr[1], bdaddr.addr[0], bdaddr.type); /* 3 2 1 0 idx */ @@ -1901,12 +1907,13 @@ int uapi_hfp_disconnect(void) return ret; } -int uapi_hfp_connect(void) +int uapi_hfp_connect_(void) { int ret; - bd_addr_t bdaddr={0}; - get_phone_addr(&bdaddr); - if(false==OHOS::uapi_get_acl_connect_state()) + bd_addr_t bdaddr={0}; + OHOS:: uapi_get_br_address(&bdaddr); + + if(0==OHOS::uapi_a2dp_snk_get_device_connect_state() && 0==uapi_hfp_connect_state()) { // ret= gap_connect_remote_device(&bdaddr); // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[gap_connect_remote_device] ret:%X", ret); @@ -1933,7 +1940,8 @@ int uapi_hfp_connect_state(void) { int ret; bd_addr_t bdaddr={0}; - get_phone_addr(&bdaddr); + OHOS:: uapi_get_br_address(&bdaddr); + ret = hfp_hf_get_device_connect_state(&bdaddr); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[hfp_connect_hfp] ret:%d", ret); if(PROFILE_STATE_CONNECTED==ret || PROFILE_STATE_CONNECTING ==ret) @@ -1946,11 +1954,31 @@ int uapi_hfp_connect_state(void) void uapi_hfp_send_DTMF_CODE(char code) { bd_addr_t bdaddr={0}; - get_phone_addr(&bdaddr); + OHOS:: uapi_get_br_address(&bdaddr); + int ret= hfp_hf_send_dtmf_tone(&bdaddr,code); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[hfp_hf_send_dtmf_tone] ret:%d", ret); } + +static uint8_t br_cmd=0; +int uapi_hfp_connect() +{ + br_cmd=BR_HFP_CONNECT; + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_BR_CONNECT,&br_cmd,sizeof(br_cmd)); + return 0; +} + + +int uapi_hfp_disconnect() +{ + br_cmd=BR_HFP_DISCONNECT; + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_BR_CONNECT,&br_cmd,sizeof(br_cmd)); + return 0; +} + + + #ifdef __cplusplus } #endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp index 19ba3ac47..f8fc69b0c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp @@ -8,6 +8,7 @@ #include "settings/include/SettingModel.h" #include "main/include/PullUpDownView.h" #include "ui_resource_string.h" +#include "classicbluetooth/include/BluetoothServiceOptionsView.h" namespace OHOS { SettingModel::SettingModel() {} @@ -80,6 +81,10 @@ namespace OHOS { PullUpDownView::GetInstance()->UpdateEarPhoneStatus(status); } + if(BluetoothServiceOptionsView::GetInstance()) + { + BluetoothServiceOptionsView::GetInstance()->Button_UPdata(); + } } // 更新蓝牙连接状态 @@ -90,5 +95,9 @@ namespace OHOS { PullUpDownView::GetInstance()->UpdateBlueToothStatus(status); } + if(BluetoothServiceOptionsView::GetInstance()) + { + BluetoothServiceOptionsView::GetInstance()->Button_UPdata(); + } } } 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 68c3e5581..0f4087425 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c @@ -304,8 +304,10 @@ void svr_ble_connstate_change_cb(unsigned short conn_id, bd_addr_t *addr, gap_bl WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GAP_BLE_STATE_DISCONNECTED!!! \r\n"); // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GAP_BLE_STATE_DISCONNECTED!!! svr_alipay_get_adv_start_state %d alipay_get_binding_status:%d\r\n",svr_alipay_get_adv_start_state(),alipay_get_binding_status()); // if(AdverFlag == true){ - free_ble_data(); - svr_ble_adv_start(); + free_ble_data(); + if(cm_custom_ble_service_on_flag()) + svr_ble_adv_start(); + ble_disconnect_ok(); // } } else { @@ -363,13 +365,17 @@ void svr_pair_result_cbt_cb(uint16_t conn_id, const bd_addr_t *addr, errcode_t s }else{ - if(false==(bt_is_acl_connected(addr))) + + bd_addr_t bdaddr={0}; + uapi_get_br_address(&bdaddr); + if(false==(bt_is_acl_connected(&bdaddr))) { - int ret=gap_reconnect_media_device(&phone_addr); + int ret=gap_reconnect_media_device(&bdaddr); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "gap_reconnect_media_device!!! %X\r\n",ret); } else { + 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"); } diff --git a/code/sdk/drivers/peripheral/utils/CMakeLists.txt b/code/sdk/drivers/peripheral/utils/CMakeLists.txt index 1977a4e0f..f9ca05eb1 100644 --- a/code/sdk/drivers/peripheral/utils/CMakeLists.txt +++ b/code/sdk/drivers/peripheral/utils/CMakeLists.txt @@ -15,6 +15,7 @@ set(SOURCES set(PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR} + ${ROOT_DIR}/application/wearable/fd230app/nativeui/phoneservice/include ) set(PRIVATE_HEADER diff --git a/code/sdk/drivers/peripheral/utils/custom_cmd_service.c b/code/sdk/drivers/peripheral/utils/custom_cmd_service.c index ca43334c4..b35c2ea30 100644 --- a/code/sdk/drivers/peripheral/utils/custom_cmd_service.c +++ b/code/sdk/drivers/peripheral/utils/custom_cmd_service.c @@ -31,6 +31,11 @@ #include "custom_utils.h" +#include "BluetoothModelC.h" + +#include "PhoneServiceC.h" + + typedef struct { uint8_t cmd; @@ -194,6 +199,34 @@ static void custom_cmd_service_check_task(void const *arg) case CUSTOM_CMD_MSG_TYPE_VIBRATOR_TEST: uapi_vibrator_test(2 * 60 * 60); break; + case CUSTOM_CMD_MSG_BR_CONNECT: + + switch (mail.data[0]) + { + //hfp connect + case BR_HFP_CONNECT: + uapi_hfp_connect_(); + break; + //hfp disconnect + case BR_HFP_DISCONNECT: + uapi_hfp_disconnect_(); + break; + //a2dp connect + case BR_A2DP_CONNECT: + uapi_a2dp_snk_connect_(); + break; + //a2dp disconnect + case BR_A2DP_DISCONNECT: + uapi_a2dp_snk_disconnect_(); + break; + case BR_RECONNECT: + uapi_reconnect_(); + break; + default: + break; + } + break; + default: PRINT("Unknown CUSTOM_CMD_MSG cmd 0x%02X \r\n", mail.cmd); break; diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index 0ad7f7308..2349a7e42 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -205,6 +205,17 @@ uint32_t uapi_calendar_store_date(void); #define CUSTOM_CMD_MSG_TYPE_CROWN_TEST 0x0A #define CUSTOM_CMD_MSG_TYPE_VIBRATOR_TEST 0x0B +#define CUSTOM_CMD_MSG_BR_CONNECT 0x0C + +typedef enum { + BR_HFP_CONNECT=1, + BR_HFP_DISCONNECT, + BR_A2DP_CONNECT, + BR_A2DP_DISCONNECT, + BR_RECONNECT, + +} CUSTOM_CMD_MSG_BR_CONNECT_TYPE; + errcode_t uapi_custom_cmd_service_init(void); void do_custom_cmd_service_check_msg(int cmd, void *params, int paramlen); int uapi_delete_files(const char *file_path); diff --git a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c index a81a165c3..14871c94f 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c @@ -1052,29 +1052,25 @@ static uint32_t BLE_TEST(uint8_t *para, uint32_t paraLen, char *strCommonCmd) case 1: uapi_reconnect(); break; - // case 2: - // custom_ble_service_start(); - // break; + case 2: + custom_ble_service_start(); + break; case 3: custom_ble_service_start_(atoi( (char *)argv[1])); break; case 4: uapi_a2dp_snk_connect(); break; - // case 5: - // svr_ble_adv_stop(); - // break; - // case 6: - // uapi_disconnect_remote_device(); - // break; - // case 7: - // uapi_ble_disconnect_device(); - // break; + case 5: + svr_ble_adv_stop(); + break; + case 6: + uapi_disconnect_remote_device(); + break; + case 7: + uapi_ble_disconnect_device(); + break; - // case 3: - // gap_br_set_bt_scan_mode(GAP_SCAN_MODE_NONE, 20);; - // break; - default: break; }