From e4586c45a9f252c335f7ad4ccbcd39c88181803a Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=A2=81=E6=B8=85=E6=A2=A6?= <3449750381@qq.com> Date: Fri, 6 Dec 2024 13:14:38 +0000 Subject: [PATCH] Merge #1501 into sdk602patch0911 from refs/changes/1501/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - 表盘:优化表盘map存储 - 消息:优化信息的处理逻辑 - release V1.3.101 --- autobuild.sh | 2 +- .../nativeui/message/src/MessageModel.cpp | 229 ++++++++++-------- .../nativeui/set_dial/src/SetDialModel.cpp | 114 +++++---- .../service/ble_service/blemoder/bletest.h | 4 +- .../service/ble_service/bleservice/bleANCS.c | 51 ++-- .../service/ble_service/bleservice/bleEvent.c | 22 +- .../msg_center/src/msg_center_customer.cpp | 6 +- .../src/notify/message_notification.cpp | 2 +- .../utils/custom_fileoperate_service.c | 2 +- .../ble_at_sample/src/sample_ble_ancs.c | 48 ++-- 10 files changed, 286 insertions(+), 194 deletions(-) diff --git a/autobuild.sh b/autobuild.sh index 84258896b..50f6411d3 100755 --- a/autobuild.sh +++ b/autobuild.sh @@ -36,7 +36,7 @@ DEFAULT_RECOVERY_NAME=brandy-native-js-r DEFAULT_SSB_NAME=brandy-ssb DEFAULT_TARGET_PACK_NAME_USER=pack_brandy_native_js_user DEFAULT_APPLICATION_NAME_USER=brandy-native-js-user -DEFAULT_CUSTOM_FW_VERSION=1.3.101 +DEFAULT_CUSTOM_FW_VERSION=1.3.102 TARGET_DATABASE_PATH=code/sdk/output/brandy/database_evb diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp index 41a0f97ad..4954658ea 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -49,13 +50,27 @@ #define MESSAGE_JSON_DIR "user/userdata/message/" #define PRINTFDATA 0 +#include "notification_manager.h" +#include "msg_center.h" +#include "message_notification.h" + extern "C" errcode_t uapi_get_TIME_STR(uint32_t time, char *p_time, char date_separator, char time_separator, date_format_t format); +// #include "msg_center_customerC.h" + + +void show_notify_messgae() { + printf("show_notify_messgae\n"); + OHOS::NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_THREE); + OHOS::NotificationManager::GetInstance()->ShowNotify(OHOS::CreateMessageView, TOPIC_EVENT_MESSAGENOTE, true); +} + #ifdef __cplusplus extern "C" { #endif + static void Notify(void *args, const Topic topic, Request *request); using namespace OHOS; @@ -111,70 +126,92 @@ void MessageUnsubscribeTopic(Topic topic) { broadcastApi->Release((IUnknown *)broadcastApi); } -// 存储消息更新的定时器 -static uint32_t messageTimestamp = 0; - -static void Notify(void *args, const Topic topic, Request *request) { - UNUSED(args); - UNUSED(topic); - - if (request == NULL) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Received NULL request"); - return; - } - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Received request %d", request->msgId); - - if (request->msgId == TOPIC_EVENT_MESSAGE_UPDATA) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "Processing TOPIC_EVENT_MESSAGE_UPDATA"); +// 存储消息更新的定时器 +static uint32_t messageTimestamp = 0; + +static void Notify(void *args, const Topic topic, Request *request) { + UNUSED(args); + UNUSED(topic); + + if (request == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Received NULL request"); + return; + } + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Received request %d", request->msgId); + + if (request->msgId == TOPIC_EVENT_MESSAGE_UPDATA) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Processing TOPIC_EVENT_MESSAGE_UPDATA"); + + if (request->data == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Received NULL data"); + return; + } + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Received request %d", request->msgId); + ancs_data_info_t *messageInfo = (ancs_data_info_t *)request->data; + ancs_data_info_t messageInfo_; + + messageInfo_.title = (char*)malloc(messageInfo->titlelen + 1); + if (messageInfo_.title == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to allocate memory for title"); + return; + } + memcpy(messageInfo_.title, messageInfo->title, messageInfo->titlelen); + messageInfo_.title[messageInfo->titlelen] = '\0'; + + + messageInfo_.msg = (char*)malloc(messageInfo->msglen + 1); + if (messageInfo_.msg == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to allocate memory for message"); + free(messageInfo_.title); // Free previously allocated title + return; + } + memcpy(messageInfo_.msg, messageInfo->msg, messageInfo->msglen); + messageInfo_.msg[messageInfo->msglen] = '\0'; + + + messageInfo_.appid = messageInfo->appid; + messageInfo_.uid = messageInfo->uid; + messageInfo_.time = messageInfo->time; + messageInfo_.read = 0; + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "message_data %p %p\r\n", messageInfo_.title, messageInfo_.msg); + + + MessageModel::GetInstance().AddMessageData(&messageInfo_); + + + uint32_t currentTimestamp = OHOS::TraingModel::GetInstance()->get_current_time(); + if (currentTimestamp - messageTimestamp <= 1) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageTimestamp too short"); + free(messageInfo_.title); + free(messageInfo_.msg); + return; + } + messageTimestamp = currentTimestamp; + + + if (uapi_dev_runtime_get_train_status() || + uapi_dev_runtime_get_saveele_status() || + uapi_dev_runtime_get_respiratory_training_status()) { + + free(messageInfo_.title); + free(messageInfo_.msg); + return; + } - // 创建新的消息信息 - ancs_data_info_t *messageInfo = new (std::nothrow) ancs_data_info_t(); - if (messageInfo == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "Failed to allocate memory for ancs_data_info_t"); - return; // 直接返回,不需要释放 - } - // 复制请求数据到新的消息信息 - int rets = memcpy_s(messageInfo, sizeof(ancs_data_info_t), - (ancs_data_info_t *)request->data, request->len); - if (rets != EOK) { - delete messageInfo; // 释放内存 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "memcpy_s ancs_data_info_t failed, ret = %d", rets); - return; - } + // CustomEventPublish(TOPIC_EVENT_MESSAGENOTE, NULL, 0); - // 更新到模型里面的数组 - MessageModel::GetInstance().AddMessageData(messageInfo); + show_notify_messgae(); - // 检查时间戳 - uint32_t currentTimestamp = - OHOS::TraingModel::GetInstance()->get_current_time(); - if (currentTimestamp - messageTimestamp <= 1) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageTimestamp too short"); - delete messageInfo; // 确保释放内存 - return; - } - messageTimestamp = currentTimestamp; - - // 检查训练模式 - if (uapi_dev_runtime_get_train_status() || - uapi_dev_runtime_get_saveele_status() || - uapi_dev_runtime_get_respiratory_training_status()) { - // 在这些状态下不弹窗 - delete messageInfo; // 确保释放内存 - return; - } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Message popup sent"); - // 发送弹窗通知 - CustomEventPublish(TOPIC_EVENT_MESSAGENOTE, NULL, 0); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Message popup sent"); - delete messageInfo; // 在成功完成后释放内存 - } + free(messageInfo_.title); + free(messageInfo_.msg); + } } void saveancsdata() { // printf("saveancs\r\n"); @@ -392,45 +429,43 @@ void MessageModel::SetCurrentIndex(uint8_t index) { uint8_t MessageModel::GetCurrentIndex() { return currentIndex_; } // 增加消息项[添加数组项] -void MessageModel::AddMessageData(ancs_data_info_t *messageInfo) { - if (messageInfo == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageInfo is null"); - return; - } - - // 创建并填充 MessageData - MessageData data; - data.isRead = messageInfo->read; - data.labelDetails = messageInfo->msg; - data.labelTitle = messageInfo->title; - data.timestamp = messageInfo->time; - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, - "AddMessageData data.isRead is %d, data.labelDetails is %s, " - "data.labelTitle is %s, data.timestamp is %d", - data.isRead, data.labelDetails.c_str(), data.labelTitle.c_str(), - data.timestamp); - - // 处理时间字符串 - char labelTime[20]; - if (uapi_get_TIME_STR(data.timestamp, labelTime, '.', ':', DATE_Y_M_D_H_M) != - ERRCODE_SUCC) { - data.labelTime = "--"; // 默认值 - } else { - data.labelTime = labelTime; // 直接使用 labelTime - } - - // 添加数据到消息向量 - MessageVector.push_back(data); - - // 删除多余的数据 - if (MessageVector.size() > MaxMessageListCount) { - MessageVector.erase(MessageVector.begin(), - MessageVector.begin() + - (MessageVector.size() - MaxMessageListCount)); - } - - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageInfo add is ok"); +void MessageModel::AddMessageData(ancs_data_info_t *messageInfo) { + if (messageInfo == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageInfo is null"); + return; + } + + // 创建并填充 MessageData + MessageData data; + data.isRead = messageInfo->read; + data.labelDetails = messageInfo->msg ? messageInfo->msg : ""; + data.labelTitle = messageInfo->title ? messageInfo->title : ""; + data.timestamp = messageInfo->time; + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "AddMessageData data.isRead is %d, data.labelDetails is %s, " + "data.labelTitle is %s, data.timestamp is %u", + data.isRead, data.labelDetails.c_str(), data.labelTitle.c_str(), + data.timestamp); + + // 处理时间字符串 + char labelTime[20]; + if (uapi_get_TIME_STR(data.timestamp, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC) { + data.labelTime = "--"; // 默认值 + } else { + data.labelTime = labelTime; // 直接使用 labelTime + } + + // 添加数据到消息向量 + MessageVector.push_back(data); + + // 删除多余的数据 + if (MessageVector.size() > MaxMessageListCount) { + MessageVector.erase(MessageVector.begin(), + MessageVector.begin() + (MessageVector.size() - MaxMessageListCount)); + } + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageInfo add is ok"); } // 获取目前的项 MessageData *MessageModel::GetCurrentMessageData() { diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp index 0d6040fa2..65e11d06a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp @@ -2,6 +2,8 @@ #include "DialBinParser.h" #include "MainModel.h" #include "NativeAbility.h" +#include "bleEvent.h" +#include "bleService.h" #include "clock/include/MainClockView.h" #include "custom_runtime.h" #include "custom_utils.h" @@ -23,8 +25,6 @@ #include #include #include -#include "bleEvent.h" -#include "bleService.h" extern "C" { void check_dial_space() { OHOS::SetDialModel::GetInstance().CheckDialSpace(); } } @@ -45,60 +45,83 @@ std::unordered_map registeredDials{ }; // 表盘市场UID 对应表盘name +// 存储表盘到文件 bool SetDialModel::saveDialfile() { - FILE *fp = fopen(DIAL_ID_PATH, "wb+"); + FILE *fp = fopen(DIAL_ID_PATH, "wb"); + if (!fp) { + WEARABLE_LOGE("File I/O", "Failed to open file for writing: %s", + DIAL_ID_PATH); + return false; + } for (const auto &entry : registeredDials) { char buf[DIAL_ID_LENGTH + DIAL_NAME_LENGTH] = {0}; - memcpy_s(buf, DIAL_ID_LENGTH + DIAL_NAME_LENGTH, &entry.first, 2); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uid %d", entry.first); - memcpy_s(buf + DIAL_ID_LENGTH, DIAL_ID_LENGTH + DIAL_NAME_LENGTH, - entry.second.c_str(), entry.second.length()); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uid %s", entry.second.c_str()); - int size = fwrite(buf, 1, DIAL_ID_LENGTH + DIAL_NAME_LENGTH, fp); - if (DIAL_ID_LENGTH + DIAL_NAME_LENGTH != size) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " fwrite is fail! %d", size); + // 复制UID + memcpy_s(buf, DIAL_ID_LENGTH, &entry.first, DIAL_ID_LENGTH); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RegisterDial %d %s is ok!", ID, + "uid %d", entry.first); + + // 复制表盘名称,确保不越界 + size_t name_length = + entry.second.copy(buf + DIAL_ID_LENGTH, DIAL_NAME_LENGTH - 1); + buf[DIAL_ID_LENGTH + name_length] = '\0'; // 确保字符串以null结尾 + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RegisterDial %d %s is ok!", ID, + "uid %s", entry.second.c_str()); + + // 写入文件 + size_t size = + fwrite(buf, sizeof(char), DIAL_ID_LENGTH + DIAL_NAME_LENGTH, fp); + if (size != (DIAL_ID_LENGTH + DIAL_NAME_LENGTH)) { + WEARABLE_LOGE("File I/O", "fwrite failed! Written bytes: %zu", size); fclose(fp); return false; } else { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " fwrite is succ %d !", - entry.first); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RegisterDial %d %s is ok!", ID, + "fwrite succeeded for uid %d!", entry.first); } } fclose(fp); return true; } +// 从文件读取表盘 bool SetDialModel::readDialfile() { - FILE *fp = fopen(DIAL_ID_PATH, "rb+"); - if (fp == NULL) + FILE *fp = fopen(DIAL_ID_PATH, "rb"); + if (!fp) { + WEARABLE_LOGE("File I/O", "Failed to open file for reading: %s", + DIAL_ID_PATH); return false; + } + fseek(fp, 0, SEEK_END); - int size = ftell(fp); + long file_size = ftell(fp); fseek(fp, 0, SEEK_SET); - // char * buf=(char *)malloc(size); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " readDialfile size is %d !", size); + WEARABLE_LOGD("Log", "readDialfile size is %ld!", file_size); - while (size) { + while (file_size > 0) { uint16_t uid = 0; - if (DIAL_ID_LENGTH != fread((void *)&uid, 1, DIAL_ID_LENGTH, fp)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " fread is fail!"); + if (fread(&uid, 1, DIAL_ID_LENGTH, fp) != DIAL_ID_LENGTH) { + WEARABLE_LOGE("File I/O", "fread failed for uid!"); + break; // 读取出错,停止循环 } - - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uid %d", uid); - + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uid %d", uid); char name_buf[DIAL_NAME_LENGTH] = {0}; - if (DIAL_NAME_LENGTH != fread((void *)name_buf, 1, DIAL_NAME_LENGTH, fp)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " fread is fail!"); + if (fread(name_buf, 1, DIAL_NAME_LENGTH, fp) != DIAL_NAME_LENGTH) { + WEARABLE_LOGE("File I/O", "fread failed for name_buf!"); + break; // 读取出错,停止循环 } - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "name_buf %s", name_buf); - - if (uid != 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "name_buf %s", name_buf); + // 检查UID和名称的有效性 + if (uid != 0 && name_buf[0] != '\0') { if (!IsDialInstalled(uid)) { RegisterDial(uid, name_buf); } + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"Invalid uid or empty name. uid: %d, name: %s", uid, name_buf); } - size -= (DIAL_ID_LENGTH + DIAL_NAME_LENGTH); + + file_size -= (DIAL_ID_LENGTH + DIAL_NAME_LENGTH); } fclose(fp); @@ -414,17 +437,22 @@ void SetDialModel::UpdateDialSetting(uint16_t ID) { /*判断是否为当前表盘 如果是自定义表盘 需要更新*/ if (currentDialID == ID && ID >= 5) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "UpdateDialSetting: Current dial %d cannot be updated %d",currentDialID,ID); - reply_app_send_switchDialCmd(false); + "UpdateDialSetting: Current dial %d cannot be updated %d", + currentDialID, ID); + reply_app_send_switchDialCmd(false); return; } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UpdateDialSetting: ID %d",ID); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UpdateDialSetting: ID %d", ID); if (registeredDials.find(ID) != registeredDials.end()) { std::string dialname = registeredDials[ID]; // 根据ID找到对应的表盘名称 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UpdateDialSetting: Dial %s is already registered", dialname.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "UpdateDialSetting: Dial %s is already registered", + dialname.c_str()); // 在dialInfoList中查找同名表盘 for (size_t i = 0; i < dialInfoList.size(); i++) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "dialInfoList name %s is already registered", (dialInfoList[i].dialName).c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "dialInfoList name %s is already registered", + (dialInfoList[i].dialName).c_str()); if (dialInfoList[i].dialName == dialname) { DialSetting diagSetting; SetDialInfo &info = dialInfoList[i]; @@ -436,17 +464,20 @@ void SetDialModel::UpdateDialSetting(uint16_t ID) { MainModel::GetInstance().AddDialSetting(diagSetting, currentDialID); // 更新表盘设置 NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); - svr_ble_read_data_value_updata_noyify(); //app切换表盘增加id更新 - reply_app_send_switchDialCmd(true); + svr_ble_read_data_value_updata_noyify(); // app切换表盘增加id更新 + reply_app_send_switchDialCmd(true); return; // 更新成功后直接返回 } } //没有在列表找到名称 reply_app_send_switchDialCmd(false); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "dialInfoList name %s is already registered", dialname.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "dialInfoList name %s is already registered", + dialname.c_str()); } else { - reply_app_send_switchDialCmd(false); - WEARABLE_LOGE( WEARABLE_LOG_MODULE_APP,"SetDialModel UpdateDialSetting: Cannot find dial %d", ID); + reply_app_send_switchDialCmd(false); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "SetDialModel UpdateDialSetting: Cannot find dial %d", ID); } } @@ -530,7 +561,8 @@ void SetDialModel::LoadAllDialFromDefult(void) { SetDialInfo dialInfo{0}; int ret = ParseDialHeader(DEFULTDIAL, fullDialName, dialInfo); if (ret == 0) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Adding dial %s", fullDialName.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Adding dial %s", + fullDialName.c_str()); dialInfoList.push_back(dialInfo); } else { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h index 4612663b8..e6c95873c 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h @@ -99,7 +99,9 @@ typedef struct ancs_data_info char *title;//消息发送者 char *msg;//消息内容 int hasCode;//消息hash code - int read;//是否已读 0 未读 1 已读 + int read; //是否已读 0 未读 1 已读 + int titlelen; + int msglen; }ancs_data_info_t; struct message_infor_t diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.c index ddef52575..279b782b9 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.c @@ -174,7 +174,7 @@ uint8_t is_filtration_data(char *data) { for (size_t i = 0; i < filtration_data_count; i++) { - if (strcmp(data,filtration_data_T[i].name)==0) + if (strncmp(data,filtration_data_T[i].name,filtration_data_max_len)==0) { if(filtration_data_T[i].on) { @@ -305,53 +305,72 @@ static void ble_ancs_client_notify_source_cbk(uint8_t client_id, uint16_t conn_i //static char old_time_buf[64]={0}; static uint32_t ancs_msg_index =0; +static char title_buf[300] = {0}; +static char msg_buf[300] = {0}; +static char app_buf[70] = {0}; /* ANCS服务通知属性响应结果回调 */ static void ble_ancs_client_notification_attr_rsp_cbk(uint8_t client_id, uint16_t conn_id, ble_ancs_notification_attr_rsp_t *notify_attr_rsp, errcode_t status) { if (status == ERRCODE_BT_SUCCESS) { + if (notify_attr_rsp == NULL) { + printf("[ANCSClientNotifyATTRSPCBK]notify_attr_rsp is NULL.\r\n"); + return; + } + printf("[ANCSClientNotifyATTRSPCBK]conn_id:%d status:0x%x notify_uid:%lu\r\n", conn_id, status, notify_attr_rsp->notification_uid); ble_ancs_attr_rsp_t *node = (ble_ancs_attr_rsp_t *)notify_attr_rsp->attr_rsp_lst.head; - uint16_t att_num = 1; - char title_buf[300] = {0}; - char msg_buf[300] = {0}; - char app_buf[70] = {0}; - time_t timestamp = 0; // 初始化时间戳 + uint16_t att_num = 0; + time_t timestamp = 0; while (node != NULL) { - if (node != NULL) { + if (node->att != NULL) { printf("[ANCSClientNotifyATTRSPCBK]att id:%d length:%lu att_value:%s\r\n", node->att_id, node->att_length, node->att); - + + size_t att_length = strlen((char*)node->att); if (node->att_id == 1) { - sprintf_s(title_buf, 300, "%s", node->att); + memset_s(title_buf, 300, 0, 300); + if (att_length < 300) { + memcpy_s(title_buf, 300, node->att, att_length); + } else { + printf("标题缓冲区溢出: %s\r\n", node->att); + } } else if (node->att_id == 3) { - sprintf_s(msg_buf, 300, "%s", node->att); + memset_s(msg_buf, 300, 0,300); + if (att_length < 300) { + memcpy_s(msg_buf, 300, node->att, att_length); + } else { + printf("消息缓冲区溢出: %s\r\n", node->att); + } } else if (node->att_id == 0) { - sprintf_s(app_buf, 70, "%s", node->att); + memset_s(app_buf, 70, 0, 70); + if (att_length < 70) { + memcpy_s(app_buf,70, node->att, att_length); + } else { + printf("应用缓冲区溢出: %s\r\n", node->att); + } } else if (node->att_id == 5) { struct tm tm = {0}; - // 将 node->att 强制转换为 const char * if (strptime((const char *)node->att, "%Y%m%dT%H%M%S", &tm) != NULL) { - timestamp = mktime(&tm); // 获取时间戳 + timestamp = mktime(&tm); } else { printf("时间字符串解析失败: %s\r\n", node->att); } } } node = lnext(node); - if (att_num == notify_attr_rsp->att_num) { + att_num++; + if (att_num >= notify_attr_rsp->att_num) { break; } - att_num++; } printf("ble_ancs_client_notification_attr_rsp_cbk test\r\n"); - // 只有在成功解析时间戳后才进行后续操作 if (is_filtration_data(app_buf) && (timestamp >= subscribe_notify_creationTime)) { message_data(notify_attr_rsp->notification_uid, 0, title_buf, msg_buf, 0); } diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c index 5f86f840a..8efdd04f8 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -6544,18 +6544,24 @@ void message_data(int uid,int appid,char *title,char *msg,int hasCode) timestampe = 0; } ancs_data_info_t data; - //memset_s(&data,sizeof(ancs_data_info_t),0,sizeof(ancs_data_info_t)); + data.title=malloc(strlen(title)+1); + data.msg = malloc(strlen(msg) + 1); + memset_s(data.title, TITLE_BUF_LEN, 0, strlen(title) + 1); + memset_s(data.msg, MSG_BUF_LEN, 0, strlen(msg) + 1); + memcpy_s(data.title, TITLE_BUF_LEN + 1, title, strlen(title)); + memcpy_s(data.msg, MSG_BUF_LEN + 1, msg, strlen(msg)); - data.appid=appid; - // memcpy_s(data.title,TITLE_BUF_LEN+1,title,strlen(title)); - // memcpy_s(data.msg,MSG_BUF_LEN+1,msg,strlen(msg)); - data.title=title; - data.msg=msg; + + data.appid = appid; data.uid=uid; data.time=timestampe; data.read=0; - data.hasCode=hasCode; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"message_data\r\n"); + data.hasCode = hasCode; + + data.msglen = strlen(msg); + data.titlelen = strlen(title); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"message_data %p %p\r\n", data.title, data.msg); CustomEventPublish_TOPIC_EVENT_MESSAGENOTE(&data); return ; diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp index de6d7e4e3..d5c0eb683 100644 --- a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp @@ -2058,11 +2058,7 @@ void MsgCenterReportBtStatusToJS(uint16_t msgId) } } -void show_notify_messgae() { - printf("show_notify_messgae\n"); - NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_THREE); - NotificationManager::GetInstance()->ShowNotify(showMessageNotify, TOPIC_EVENT_MESSAGENOTE, true); -} + #endif diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp index c2e5beb99..499d79ccb 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp @@ -79,7 +79,7 @@ bool MessageViewEventListener::OnDrag(UIView &view, const DragEvent &event) { bool MessageViewEventListener::OnDragEnd(UIView &view, const DragEvent &event) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::OnDragEnd"); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - NotificationManager::GetInstance()->StopNotify(); + // NotificationManager::GetInstance()->StopNotify(); } return true; } diff --git a/code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c b/code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c index eadd410ea..bc905053e 100644 --- a/code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c +++ b/code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c @@ -192,7 +192,7 @@ static void custom_fileoperate_service_check_task(void const *arg) break; case CUSTOM_FILEOPERATE_MSG_TYPE_MESSAGE_DATA_NOTIFY: - show_notify_messgae(); + // show_notify_messgae(); break; PRINT("Unknown CUSTOM_FILE_OPERATE_MSG cmd 0x%02X \r\n", mail.cmd); diff --git a/code/sdk/protocol/bt/host/bt/bts/bt_sample/ble_profile/ble_at_sample/src/sample_ble_ancs.c b/code/sdk/protocol/bt/host/bt/bts/bt_sample/ble_profile/ble_at_sample/src/sample_ble_ancs.c index 560afcd9b..7c372586e 100644 --- a/code/sdk/protocol/bt/host/bt/bts/bt_sample/ble_profile/ble_at_sample/src/sample_ble_ancs.c +++ b/code/sdk/protocol/bt/host/bt/bts/bt_sample/ble_profile/ble_at_sample/src/sample_ble_ancs.c @@ -76,30 +76,32 @@ static void ble_ancs_client_notify_source_cbk(uint8_t client_id, uint16_t conn_i } /* ANCS服务通知属性响应结果回调 */ -static void ble_ancs_client_notification_attr_rsp_cbk(uint8_t client_id, uint16_t conn_id, - ble_ancs_notification_attr_rsp_t *notify_attr_rsp, errcode_t status) -{ - if (status == ERRCODE_BT_SUCCESS) { - bts_info("[ANCSClientNotifyATTRSPCBK]conn_id:%d status:0x%x notify_uid:%lu\r\n", - conn_id, status, notify_attr_rsp->notification_uid); +static void ble_ancs_client_notification_attr_rsp_cbk(uint8_t client_id, uint16_t conn_id, + ble_ancs_notification_attr_rsp_t *notify_attr_rsp, errcode_t status) +{ + if (status == ERRCODE_BT_SUCCESS) { + if (notify_attr_rsp == NULL) { + bts_error("[ANCSClientNotifyATTRSPCBK]notify_attr_rsp is NULL.\r\n"); + return; + } - ble_ancs_attr_rsp_t *node = (ble_ancs_attr_rsp_t *)notify_attr_rsp->attr_rsp_lst.head; - uint16_t att_num = 1; - while (node != NULL) { - if (node != NULL) { - bts_info_no_header("[ANCSClientNotifyATTRSPCBK]att id:%d length:%lu att_value:%s\r\n", - node->att_id, node->att_length, node->att); - } - node = lnext(node); - if (att_num == notify_attr_rsp->att_num) { - break; - } - att_num = att_num + 1; - } - } else { - bts_error("[ANCSClientNotifyATTRSPCBK]conn_id:%d status:0x%x.\r\n", - conn_id, status); - } + bts_info("[ANCSClientNotifyATTRSPCBK]conn_id:%d status:0x%x notify_uid:%lu\r\n", + conn_id, status, notify_attr_rsp->notification_uid); + + ble_ancs_attr_rsp_t *node = (ble_ancs_attr_rsp_t *)notify_attr_rsp->attr_rsp_lst.head; + uint16_t att_num = 0; // 初始化为0 + while (node != NULL && att_num < notify_attr_rsp->att_num) { + if (node->att != NULL) { // 确保 att 不为 NULL + bts_info_no_header("[ANCSClientNotifyATTRSPCBK]att id:%d length:%lu att_value:%s\r\n", + node->att_id, node->att_length, node->att); + } + node = lnext(node); + att_num++; + } + } else { + bts_error("[ANCSClientNotifyATTRSPCBK]conn_id:%d status:0x%x.\r\n", + conn_id, status); + } } /* ANCS服务应用属性响应结果回调 */ -- 2.17.1