}
}
//上报蓝牙耳机连接状态
- GraphicService::GetInstance()-> PostGraphicEvent(std::bind(ln_bt_report_earphone_connection_status));
+ GraphicService::GetInstance()-> PostGraphicEvent([]() { ln_bt_report_earphone_connection_status(true); }); // 显示弹窗
}
uint8_t A2dpSrcPlayingState=0;
}
// 上报蓝牙耳机连接状态
- int ln_bt_report_earphone_connection_status(void)
+ int ln_bt_report_earphone_connection_status(bool show_status)
{
// 只有在已连接状态下才能发送状态报告
if (ln_ws_get_connection_state() != 2)
OHOS::BluetoothModel *bluetoothModel = OHOS::BluetoothModel::GetInstance();
bd_addr_t *lastAddr = bluetoothModel->GetLastConnedAddr();
+ const char *bluetoothStatus = nullptr;
+ int cmd = show_status ? LN_HTTP_SERVICE_CMD_BLUETOOTH_STATUS_REPORT : LN_HTTP_SERVICE_CMD_BLUETOOTH_STATUS_REPORT_NO_POPUP;
+
// 检查地址是否有效
if (lastAddr == nullptr)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_bt_report_earphone_connection_status: lastAddr is nullptr");
- char *bluetoothStatus = "DISCONNECTED";
- do_ln_http_server_send_data(LN_HTTP_SERVICE_CMD_BLUETOOTH_STATUS_REPORT, bluetoothStatus, strlen(bluetoothStatus));
- return 0;
+ bluetoothStatus = "DISCONNECTED";
}
-
// 检查地址是否为空(全0)
- if ((lastAddr->addr[0] == 0) && (lastAddr->addr[1] == 0) &&
+ else if ((lastAddr->addr[0] == 0) && (lastAddr->addr[1] == 0) &&
(lastAddr->addr[2] == 0) && (lastAddr->addr[3] == 0) &&
(lastAddr->addr[4] == 0) && (lastAddr->addr[5] == 0))
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_bt_report_earphone_connection_status: lastAddr is empty");
- char *bluetoothStatus = "DISCONNECTED";
- do_ln_http_server_send_data(LN_HTTP_SERVICE_CMD_BLUETOOTH_STATUS_REPORT, bluetoothStatus, strlen(bluetoothStatus));
- return 0;
+ bluetoothStatus = "DISCONNECTED";
+ }
+ else
+ {
+ // 检查A2DP连接状态(耳机真实连接状态)
+ int a2dpState = a2dp_src_get_device_connect_state(lastAddr);
+ bool isEarphoneConnected = (a2dpState == PROFILE_STATE_CONNECTED);
+
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_bt_report_earphone_connection_status: a2dpState=%d, isEarphoneConnected=%d",
+ a2dpState, isEarphoneConnected);
+
+ bluetoothStatus = isEarphoneConnected ? "CONNECTED" : "DISCONNECTED";
}
- // 检查A2DP连接状态(耳机真实连接状态)
- int a2dpState = a2dp_src_get_device_connect_state(lastAddr);
- bool isEarphoneConnected = (a2dpState == PROFILE_STATE_CONNECTED);
-
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_bt_report_earphone_connection_status: a2dpState=%d, isEarphoneConnected=%d",
- a2dpState, isEarphoneConnected);
+ // 根据 show_status 选择对应的命令,通过消息队列发送
+ do_ln_http_server_send_data(cmd, (char *)bluetoothStatus, strlen(bluetoothStatus));
// 检查当前是否在蓝牙界面,如果在则设置标志
OHOS::ThunderBirdMainView *mainView = OHOS::ThunderBirdMainView::GetInstance();
isInBlueView = (currentView == 7);
}
- if (isEarphoneConnected)
- {
- // 蓝牙已连接,上报蓝牙状态
- char *bluetoothStatus = "CONNECTED";
- do_ln_http_server_send_data(LN_HTTP_SERVICE_CMD_BLUETOOTH_STATUS_REPORT, bluetoothStatus, strlen(bluetoothStatus));
-
- // 如果当前在蓝牙界面,设置标志表示已上报
- if (isInBlueView && mainView != nullptr) {
- mainView->m_btStatusReportedInBlueView_ = true;
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_bt_report_earphone_connection_status: 在蓝牙界面内上报状态,设置标志");
- }
- }
- else
- {
- // 蓝牙已断开,上报蓝牙状态
- char *bluetoothStatus = "DISCONNECTED";
- do_ln_http_server_send_data(LN_HTTP_SERVICE_CMD_BLUETOOTH_STATUS_REPORT, bluetoothStatus, strlen(bluetoothStatus));
-
- // 如果当前在蓝牙界面,设置标志表示已上报
- if (isInBlueView && mainView != nullptr) {
- mainView->m_btStatusReportedInBlueView_ = true;
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_bt_report_earphone_connection_status: 在蓝牙界面内上报状态,设置标志");
- }
+ // 如果当前在蓝牙界面,设置标志表示已上报
+ if (isInBlueView && mainView != nullptr) {
+ mainView->m_btStatusReportedInBlueView_ = true;
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ln_bt_report_earphone_connection_status: 在蓝牙界面内上报状态,设置标志");
}
return 0;
int ln_bt_get_last_conned_device_battery_level(void);
// 上报蓝牙耳机连接状态
-int ln_bt_report_earphone_connection_status(void);
+int ln_bt_report_earphone_connection_status(bool show_status);
// 增加耳机音量(按键方式,音量调节值由耳机固件决定,通常为固定步进值)
int ln_bt_earphone_volume_up(void);
if (model != nullptr && model->m_wasInDownloadView)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::OnStart: 从下载界面返回,上报蓝牙连接状态");
- ln_bt_report_earphone_connection_status();
+ ln_bt_report_earphone_connection_status(false); // 不需要弹窗
model->m_wasInDownloadView = false; // 清除标志位
}
View<ThunderBirdPresenter>::OnStart();
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::ChangeView: 蓝牙界面已上报过状态,退出时不再上报");
m_btStatusReportedInBlueView_ = false; // 清除标志
} else {
- ln_bt_report_earphone_connection_status();
+ ln_bt_report_earphone_connection_status(true); // 显示弹窗
}
}
if(showView == THUNDERBIRD_BLUEVIEW )
}
else if(mail.cmd == LN_HTTP_SERVICE_CMD_BLUETOOTH_STATUS_REPORT)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[LN_HTTP_SERVICE_CMD_BLUETOOTH_STATUS_REPORT] 蓝牙状态上报");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[LN_HTTP_SERVICE_CMD_BLUETOOTH_STATUS_REPORT] 蓝牙状态上报(需要弹窗)");
if (mail.data && mail.len > 0)
{
/* 确保字符串以\0结尾,避免乱码 */
{
memcpy(bluetooth_status, mail.data, mail.len);
bluetooth_status[mail.len] = '\0';
- ln_send_bluetooth_status_report(bluetooth_status);
+ ln_send_bluetooth_status_report(bluetooth_status, true); /* 需要弹窗 */
free(bluetooth_status);
}
}
}
+ else if(mail.cmd == LN_HTTP_SERVICE_CMD_BLUETOOTH_STATUS_REPORT_NO_POPUP)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[LN_HTTP_SERVICE_CMD_BLUETOOTH_STATUS_REPORT_NO_POPUP] 蓝牙状态上报(不需要弹窗)");
+ if (mail.data && mail.len > 0)
+ {
+ /* 确保字符串以\0结尾,避免乱码 */
+ char *bluetooth_status = (char *)malloc(mail.len + 1);
+ if (bluetooth_status)
+ {
+ memcpy(bluetooth_status, mail.data, mail.len);
+ bluetooth_status[mail.len] = '\0';
+ ln_send_bluetooth_status_report(bluetooth_status, false); /* 不需要弹窗 */
+ free(bluetooth_status);
+ }
+ }
+ }
+
else if (mail.cmd == LN_HTTP_SERVICE_CMD_CHAT_SESSION_START)
{
printf("LN_HTTP_SERVICE_CMD_CHAT_SESSION_START:语音对话流开始\n");
#define LN_HTTP_SERVICE_CMD_WS_EXIT_SLEEP 0x1014 /* 退出休眠 */
//蓝牙状态上报相关命令
-#define LN_HTTP_SERVICE_CMD_BLUETOOTH_STATUS_REPORT 0x1015 /* 蓝牙状态上报 */
+#define LN_HTTP_SERVICE_CMD_BLUETOOTH_STATUS_REPORT 0x1015 /* 蓝牙状态上报(需要弹窗) */
+#define LN_HTTP_SERVICE_CMD_BLUETOOTH_STATUS_REPORT_NO_POPUP 0x101C /* 蓝牙状态上报(不需要弹窗) */
/* 语音对话流相关命令 */
#define LN_HTTP_SERVICE_CMD_CHAT_SESSION_START 0x1016 /* 语音对话流开始 */
/* 解析蓝牙解绑命令 */
void ln_parse_bluetooth_unbind(const char *json_str, int json_len);
/* 发送蓝牙状态上报(使用消息队列方式) */
-void ln_send_bluetooth_status_report(const char *bluetooth_status);
+void ln_send_bluetooth_status_report(const char *bluetooth_status, bool show_status);
/* 设置睡眠模式状态标志位 */
void uapi_set_sleep_mode_active(bool active);
/* 获取睡眠模式状态标志位 */
/* 发送蓝牙状态上报 BluetoothStatusReport(内部实现,通过WebSocket发送) */
static int ln_ws_send_bluetooth_status_report(const char *bluetooth_address, const char *bluetooth_name,
- int battery_level, const char *bluetooth_status, const char *msg)
+ int battery_level, const char *bluetooth_status, const char *msg, bool show_status)
{
if (ln_ws_get_connection_state() != 2)
{
cJSON_AddNumberToObject(data, "batteryLevel", battery);
cJSON_AddStringToObject(data, "bluetoothStatus", (bluetooth_status && bluetooth_status[0]) ? bluetooth_status : "");
+ cJSON_AddBoolToObject(data, "showStatus", show_status);
cJSON_AddStringToObject(data, "message", msg ? msg : "");
cJSON_AddItemToObject(json, "data", data);
}
/* 发送蓝牙状态上报(使用消息队列方式) */
-void ln_send_bluetooth_status_report(const char *bluetooth_status)
+void ln_send_bluetooth_status_report(const char *bluetooth_status, bool show_status)
{
if (!bluetooth_status || !bluetooth_status[0])
{
char *msg = NULL;
if(strcmp(bluetooth_status, BT_STATUS_CONNECTED) == 0)
{
- msg = "蓝牙已连接";
+ msg = "蓝牙连接成功";
}
else if(strcmp(bluetooth_status, BT_STATUS_CONNECTING) == 0)
{
ln_get_bluetooth_device_name(),
ln_get_bluetooth_device_battery_level(),
bluetooth_status,
- msg);
+ msg,
+ show_status);
}
/* 解析蓝牙连接命令 BluetoothConnect */