From: luozheng <1732036298@qq.com> Date: Mon, 1 Dec 2025 13:21:04 +0000 (+0800) Subject: 蓝牙耳机页面优化 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=b04212597b63358f233594b9eacd25f8fce8ce56;p=mirrors%2FFD230.git 蓝牙耳机页面优化 --- diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/bluetooth/src/BluetoothModel.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/bluetooth/src/BluetoothModel.cpp index f09f6954a..eab84badd 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/bluetooth/src/BluetoothModel.cpp @@ -816,11 +816,6 @@ void BtGapPairStatusChangedCallback(const bd_addr_t *bdAddr, int status) bdAddr->addr[3], bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0], status); /* addr下标 0 1 2 3 */ if(status == GAP_PAIR_NONE){ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "取消配对"); - if (ln_ws_get_connection_state() == 2) - { - char *bluetoothStatus = "UNBIND_SUCCESS"; - do_ln_http_server_send_data(LN_HTTP_SERVICE_CMD_BLUETOOTH_STATUS_REPORT, bluetoothStatus, strlen(bluetoothStatus)); - } } else if(status == GAP_PAIR_PAIRING){ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "正在配对"); } else if(status == GAP_PAIR_PAIRED){ @@ -917,13 +912,6 @@ static void ACLConnectionSuss(const bd_addr_t &bdAddr) //亮屏操作 uapi_set_screen_on_api(); - - if (ln_ws_get_connection_state() == 2) - { - //蓝牙已连接,上报蓝牙状态 - char *bluetoothStatus = "CONNECTED"; - do_ln_http_server_send_data(LN_HTTP_SERVICE_CMD_BLUETOOTH_STATUS_REPORT, bluetoothStatus, strlen(bluetoothStatus)); - } ThunderBirdMainView *thunderBirdMainView = ThunderBirdMainView::GetInstance(); if (thunderBirdMainView == nullptr) @@ -956,13 +944,6 @@ static void ACLConnectionFail(const bd_addr_t &bdAddr) //亮屏操作 uapi_set_screen_on_api(); - - if (ln_ws_get_connection_state() == 2) - { - //蓝牙已断开,上报蓝牙状态 - char *bluetoothStatus = "DISCONNECTED"; - do_ln_http_server_send_data(LN_HTTP_SERVICE_CMD_BLUETOOTH_STATUS_REPORT, bluetoothStatus, strlen(bluetoothStatus)); - } ThunderBirdMainView *thunderBirdMainView = ThunderBirdMainView::GetInstance(); if (thunderBirdMainView == nullptr) @@ -1146,6 +1127,8 @@ static void A2dpSrcConnectstateChanged(bd_addr_t *bdAddr, int connState) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "a2dp disc: gap_br_set_bt_scan_mode ret = 0x%x", ret); } } + //上报蓝牙耳机连接状态 + GraphicService::GetInstance()-> PostGraphicEvent(std::bind(ln_bt_report_earphone_connection_status)); } static void A2dpSrcPlayingStateChanged(bd_addr_t *bdAddr, int playState) diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/bluetooth/src/Ln_Bluetooth_apiC.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/bluetooth/src/Ln_Bluetooth_apiC.cpp index 2efc67ece..466acbe68 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/bluetooth/src/Ln_Bluetooth_apiC.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/bluetooth/src/Ln_Bluetooth_apiC.cpp @@ -18,7 +18,7 @@ namespace OHOS { GraphicTimer *g_stopScanHandle_ln = nullptr; - static constexpr uint64_t MS_SCAN_TIME = 25 * 1000; // 最大扫描时间25秒 + static constexpr uint64_t MS_SCAN_TIME = 15 * 1000; // 最大扫描时间25秒 static constexpr uint64_t MS_SCAN_INTERVAL = 1 * 1000; // 每秒检查一次 static constexpr uint32_t MIN_SCAN_SECONDS = 10; // 最少扫描10秒 static uint32_t g_scanElapsedSeconds = 0; // 已扫描秒数 @@ -379,6 +379,9 @@ extern "C" // 检查AVRCP连接状态 if (avrcpInf.avrcp_srv_conn_stat != PROFILE_STATE_CONNECTED) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_bt_earphone_set_volume: AVRCP not connected"); + //尝试连接一次AVRCP服务 + uint32_t ret = avrcp_ct_connect(&avrcpInf.bd_addr); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_bt_earphone_get_volume: connect AVRCP, ret=%d", ret); return -1; } @@ -410,6 +413,9 @@ extern "C" // 检查AVRCP连接状态 if (avrcpInf.avrcp_srv_conn_stat != PROFILE_STATE_CONNECTED) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_bt_earphone_get_volume: AVRCP not connected"); + //尝试连接一次AVRCP服务 + uint32_t ret = avrcp_ct_connect(&avrcpInf.bd_addr); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_bt_earphone_get_volume: connect AVRCP, ret=%d", ret); return -1; } diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/phoneservice/src/PhoneAudio.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/phoneservice/src/PhoneAudio.cpp index 665d1462f..813d26e9f 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/phoneservice/src/PhoneAudio.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/phoneservice/src/PhoneAudio.cpp @@ -165,7 +165,7 @@ int32 PhoneAudioManagerSetDeviceConnState(AudioDeviceType deviceType, AudioDevic return AUDIO_ERROR; } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%s] line:%d success, deviceType = 0x%x connectState = %d", + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%s] line:%d success, deviceType = 0x%x connectState = %d", __FUNCTION__, __LINE__, deviceType, connectState); return AUDIO_SUCCESS; } diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueListAdapter.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueListAdapter.cpp index f2d48a457..67a863c77 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueListAdapter.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueListAdapter.cpp @@ -48,7 +48,7 @@ ThunderBirdBlueDeviceItemView::~ThunderBirdBlueDeviceItemView() void ThunderBirdBlueDeviceItemView::SetupChildViews() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetupChildViews"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetupChildViews"); borderImage_.SetPosition(0, 0, ITEM_WIDTH, ITEM_HEIGHT); borderImage_.SetStyle(STYLE_BACKGROUND_COLOR, COLOR_TEXT_GRAY); @@ -98,7 +98,7 @@ void ThunderBirdBlueDeviceItemView::SetDeviceInfo(const BluetoothCaseInfo& info, // 设置分组标题 void ThunderBirdBlueDeviceItemView::SetSectionHeader(const char* title) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetSectionHeader title=%s", title); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetSectionHeader title=%s", title); isSectionHeader_ = true; isConnected_ = false; @@ -119,7 +119,7 @@ void ThunderBirdBlueDeviceItemView::SetSectionHeader(const char* title) void ThunderBirdBlueDeviceItemView::SetSelected(bool selected) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetSelected=%d isSectionHeader=%d", selected, isSectionHeader_); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetSelected=%d isSectionHeader=%d", selected, isSectionHeader_); isSelected_ = selected; @@ -151,7 +151,7 @@ BluetoothCaseInfo* ThunderBirdBlueDeviceItemView::GetDeviceInfo(void) ThunderBirdBlueListAdapter::ThunderBirdBlueListAdapter() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdBlueListAdapter create"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdBlueListAdapter create"); RefreshDeviceData(); } @@ -167,7 +167,7 @@ ThunderBirdBlueListAdapter::~ThunderBirdBlueListAdapter() void ThunderBirdBlueListAdapter::RefreshDeviceData() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RefreshDeviceData"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RefreshDeviceData"); BuildDisplayList(); // 如果列表不为空且没有选中项,默认选中第一个设备项 @@ -229,7 +229,7 @@ void ThunderBirdBlueListAdapter::BuildDisplayList() item.isSelected = false; displayList_.push_back(item); connectedCount++; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Added my device (connected): %s", device.deviceName); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Added my device (connected): %s", device.deviceName); } // 第三步:再添加未连接的设备(如果还有空间) @@ -243,7 +243,7 @@ void ThunderBirdBlueListAdapter::BuildDisplayList() item.isSelected = false; displayList_.push_back(item); connectedCount++; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Added my device (unconnected): %s", device.deviceName); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Added my device (unconnected): %s", device.deviceName); } } @@ -285,13 +285,13 @@ void ThunderBirdBlueListAdapter::BuildDisplayList() uint16_t ThunderBirdBlueListAdapter::GetCount() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetCount=%d", displayList_.size()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetCount=%d", displayList_.size()); return static_cast(displayList_.size()); } UIView* ThunderBirdBlueListAdapter::GetView(UIView* inView, int16_t index) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetView index=%d inView=%p listSize=%d", + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetView index=%d inView=%p listSize=%d", index, inView, displayList_.size()); if (index < 0 || index >= static_cast(displayList_.size())) { @@ -309,7 +309,7 @@ UIView* ThunderBirdBlueListAdapter::GetView(UIView* inView, int16_t index) return nullptr; } } else { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Reusing existing item view"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reusing existing item view"); item = static_cast(inView); } @@ -317,15 +317,15 @@ UIView* ThunderBirdBlueListAdapter::GetView(UIView* inView, int16_t index) auto it = displayList_.begin(); std::advance(it, index); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetView type=%d", static_cast(it->type)); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetView type=%d", static_cast(it->type)); switch (it->type) { case DeviceItemType::SECTION_HEADER_CONNECTED: - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Setting SECTION_HEADER_CONNECTED"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Setting SECTION_HEADER_CONNECTED"); item->SetSectionHeader("我的设备"); break; case DeviceItemType::SECTION_HEADER_NEARBY: - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Setting SECTION_HEADER_NEARBY"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Setting SECTION_HEADER_NEARBY"); item->SetSectionHeader("附近的设备"); break; case DeviceItemType::DEVICE_CONNECTED: { @@ -348,7 +348,7 @@ UIView* ThunderBirdBlueListAdapter::GetView(UIView* inView, int16_t index) item->SetViewIndex(index); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetView done, returning item=%p", item); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetView done, returning item=%p", item); return item; } diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueView.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueView.cpp index 5c081fb05..4c2401550 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueView.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueView.cpp @@ -480,18 +480,18 @@ namespace OHOS // 显示设备列表 if (DeviceList != nullptr && deviceListAdapter_ != nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Setting up DeviceList"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Setting up DeviceList"); // 刷新设备列表数据 deviceListAdapter_->RefreshDeviceData(); // 确保适配器已设置 DeviceList->SetAdapter(deviceListAdapter_); - DeviceList->SetStartIndex(0); + DeviceList->ScrollTo(0); DeviceList->SetPosition(60, 70, 240, 170); // 调整位置 DeviceList->SetVisible(true); DeviceList->RefreshList(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DeviceList visible, count=%d", + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DeviceList visible, count=%d", deviceListAdapter_->GetCount()); } else @@ -741,7 +741,7 @@ namespace OHOS void ThunderBirdBlueView::RefreshDeviceList(void) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RefreshDeviceList called"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RefreshDeviceList called"); if (DeviceList == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DeviceList nullptr!"); @@ -760,7 +760,7 @@ namespace OHOS DeviceList->SetAdapter(deviceListAdapter_); DeviceList->RefreshList(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RefreshDeviceList done, count=%d", + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RefreshDeviceList done, count=%d", deviceListAdapter_->GetCount()); } diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp index 62fa00031..01cabe578 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp @@ -888,7 +888,8 @@ namespace OHOS ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_BLUEVIEW, ThunderBirdBlueView::THUNDERBIRD_BULEVIEW_SREACHING); break; case ThunderBirdBlueView::THUNDERBIRD_BULEVIEW_DISCONNECT_SUCCESS: - ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_STATUS_SHOW); + //重新发送连接操作 + ThunderBirdBlueView::GetInstance()->OnConnectFailed(); break; case ThunderBirdBlueView::THUNDERBIRD_BULEVIEW_DEVICE_LIST: // ThunderBirdBlueView::GetInstance()->OnKeyUp();// 音量+键:选择上一个设备 @@ -920,6 +921,10 @@ namespace OHOS //蓝牙已断开,返回搜索界面,提示用户重新搜索 ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_BLUEVIEW, ThunderBirdBlueView::THUNDERBIRD_BULEVIEW_DEVICE_LIST); break; + case ThunderBirdBlueView::THUNDERBIRD_BULEVIEW_DISCONNECT_CONFIRM: + //断连询问界面,按下音量-,退到连接成功界面 + ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_BLUEVIEW, ThunderBirdBlueView::THUNDERBIRD_BULEVIEW_CONNECT_SUCCESS); + break; case ThunderBirdBlueView::THUNDERBIRD_BULEVIEW_DEVICE_LIST: ThunderBirdBlueView::GetInstance()->OnKeyDown();// 音量-键:选择下一个设备 break;