From 6bbae389215f8b3bde7338bc2a3ad530d2d579c5 Mon Sep 17 00:00:00 2001 From: xue <2144439972@qq.com> Date: Thu, 16 Oct 2025 17:23:01 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E6=96=87=E6=9C=AC=E4=B9=B1?= =?utf8?q?=E7=A0=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/uiservice/src/ui_service.cpp | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp index 0449d597c..d8e4c8020 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp @@ -570,9 +570,39 @@ void HandBindAndUnbindNotify(Request *request) // 更新文本内容通知 void HandTextUpdateNotify(Request *request) { - std::string value(static_cast(request->data), request->len); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandTextUpdateNotify msg_id = %d, len = %d", request->msgId, request->len); + + // 检查数据有效性 + if (request->data == nullptr || request->len <= 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandTextUpdateNotify: invalid data or length"); + return; + } + + // 确保字符串以null结尾,避免乱码 + std::string value; + if (request->len > 0) { + const char* data = static_cast(request->data); + if (data[request->len - 1] == '\0') { + value = std::string(data, request->len - 1); + } else { + value = std::string(data, request->len); + } + } + + // 验证字符串是否包含有效字符 + if (value.empty() || value.find_first_not_of(" \t\n\r") == std::string::npos) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandTextUpdateNotify: text string is empty or contains only whitespace"); + return; + } + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandTextUpdateNotify text = %s", value.c_str()); + + // 创建字符串副本,避免const_cast问题 + std::string textCopy = value; GraphicService::GetInstance()->PostGraphicEvent( - std::bind(&OHOS::ThunderBirdModel::SetTextStr,OHOS::ThunderBirdModel::GetInstance(),const_cast(value.c_str()))); + [textCopy]() { + OHOS::ThunderBirdModel::GetInstance()->SetTextStr(const_cast(textCopy.c_str())); + }); } // 下载文件通知 -- 2.17.1