// 更新文本内容通知
void HandTextUpdateNotify(Request *request)
{
- std::string value(static_cast<char*>(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<const char*>(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<char*>(value.c_str())));
+ [textCopy]() {
+ OHOS::ThunderBirdModel::GetInstance()->SetTextStr(const_cast<char*>(textCopy.c_str()));
+ });
}
// 下载文件通知