From 8f8ec0012486cdb6e90bb894db1ebd6050ba5291 Mon Sep 17 00:00:00 2001 From: Caisking Date: Mon, 8 Sep 2025 20:04:23 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8D=E8=A1=A8=E7=9B=98=E4=B8=8B?= =?utf8?q?=E8=BD=BD=E8=B7=AF=E5=BE=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/set_dial/src/SetDialModel.cpp | 4 +- .../ble_service/blemoder/bleInstruct.cpp | 2 +- .../ble_service/bleservice/bleEvent.c | 180 ++++++++++-------- 3 files changed, 106 insertions(+), 80 deletions(-) diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_dial/src/SetDialModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_dial/src/SetDialModel.cpp index ec89ed794..ddc328040 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_dial/src/SetDialModel.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_dial/src/SetDialModel.cpp @@ -1007,9 +1007,9 @@ bool check_dial_freespace_(uint16_t id, uint32_t dial_size) { } void ble_get_dial_path_(char *buf, uint16_t id) { - char *path = - (char *)OHOS::SetDialModel::GetInstance().GetSaveDir(id, 0).c_str(); + char *path =(char *)OHOS::SetDialModel::GetInstance().GetSaveDir(id, 0).c_str(); memcpy(buf, path, strlen(path) + 1); + printf("ble_get_dial_path_ %s\n", path); return; } diff --git a/code/sdk/zhihui/services/ble_service/blemoder/bleInstruct.cpp b/code/sdk/zhihui/services/ble_service/blemoder/bleInstruct.cpp index a3e9a090d..5bf13bf79 100644 --- a/code/sdk/zhihui/services/ble_service/blemoder/bleInstruct.cpp +++ b/code/sdk/zhihui/services/ble_service/blemoder/bleInstruct.cpp @@ -72,7 +72,7 @@ extern "C" { // #ifdef FD230 -#define DIAL_DATA_DIR NULL +#define DIAL_DATA_DIR "/user/dial/offline_dial" #define TAR_PATH EXC_TAR_PATH diff --git a/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c b/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c index 845156294..4378e2db9 100644 --- a/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c +++ b/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c @@ -7679,99 +7679,125 @@ errcode_t decode_single_dial_info(ble_read_data *buffer_handle) } static errcode_t install_dial(void) { - char *lzmapkgname =uapi_dev_runtime_get_dialname(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"install %s\n",lzmapkgname); - char *lzmaindex = strstr(lzmapkgname,".lzma"); - if (lzmaindex != NULL) - { - struct stat info; - if (stat(get_dial_path(), &info) != 0) - { - if (mkdir(get_dial_path(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) - { - return ERRCODE_FAIL; // - } - } + char *lzmapkgname = uapi_dev_runtime_get_dialname(); + // 增加初始参数校验打印 + if (lzmapkgname == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 错误:获取到的表盘包名为空\n"); + return ERRCODE_FAIL; + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 开始安装表盘,包名:%s\n", lzmapkgname); - char dial_basename[64]={0}; - int dial_basenamelen = (lzmaindex - lzmapkgname); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"dial_basenamelen %d\n",dial_basenamelen); - if (dial_basenamelen>0 ) - { - memcpy_s(dial_basename,sizeof(dial_basename),lzmapkgname,dial_basenamelen); - } - else{ + // 检查是否为lzma格式包 + char *lzmaindex = strstr(lzmapkgname, ".lzma"); + if (lzmaindex == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 错误:包名中未找到.lzma后缀,不是有效压缩包\n"); + return ERRCODE_FAIL; + } + + // 创建表盘目录(若不存在) + struct stat info; + if (stat(get_dial_path(), &info) != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 表盘目录不存在,尝试创建...\n"); + if (mkdir(get_dial_path(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 错误:创建表盘目录失败\n"); return ERRCODE_FAIL; } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"dial_basename %s\n",dial_basename); - char dialbin_filepath[128]={0}; - if(ble_dial_uid>5) - { - if (get_dial_file_path(dial_basename,strlen(dial_basename),dialbin_filepath,sizeof(dialbin_filepath)) != ERRCODE_SUCC) - { - return ERRCODE_FAIL; - } - } - else - { - if (get_custom_dial_file_path(ble_dial_uid,dial_basename,strlen(dial_basename),dialbin_filepath,sizeof(dialbin_filepath)) != ERRCODE_SUCC) - { - return ERRCODE_FAIL; - } - } - + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 表盘目录创建成功\n"); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 表盘目录已存在,无需创建\n"); + } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"dialbin_filepath %s\n",dialbin_filepath); - char lzma_filepath[128]={0}; - if (get_file_recv_file_path(lzmapkgname,strlen(lzmapkgname),lzma_filepath,sizeof(lzma_filepath)) != ERRCODE_SUCC) - { + // 解析表盘基础名称(去除.lzma后缀) + char dial_basename[64] = {0}; + int dial_basenamelen = lzmaindex - lzmapkgname; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 解析基础名称长度:%d\n", dial_basenamelen); + if (dial_basenamelen <= 0 || dial_basenamelen >= sizeof(dial_basename)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 错误:基础名称长度无效(%d),超出缓冲区大小\n", dial_basenamelen); + return ERRCODE_FAIL; + } + memcpy_s(dial_basename, sizeof(dial_basename), lzmapkgname, dial_basenamelen); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 解析到表盘基础名称:%s\n", dial_basename); + + // 确定解压后bin文件路径 + char dialbin_filepath[128] = {0}; + if (ble_dial_uid > 5) { + if (get_dial_file_path(dial_basename, strlen(dial_basename), dialbin_filepath, sizeof(dialbin_filepath)) != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 错误:获取常规表盘文件路径失败\n"); + return ERRCODE_FAIL; + } + } else { + if (get_custom_dial_file_path(ble_dial_uid, dial_basename, strlen(dial_basename), dialbin_filepath, sizeof(dialbin_filepath)) != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 错误:获取自定义表盘文件路径失败\n"); return ERRCODE_FAIL; } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"lzma_filepath %s\n",lzma_filepath); + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 解压目标bin文件路径:%s\n", dialbin_filepath); - errcode_t ret = uapi_dial_pkg_decompress(lzma_filepath,dialbin_filepath); + // 确定源lzma文件路径 + char lzma_filepath[128] = {0}; + if (get_file_recv_file_path(lzmapkgname, strlen(lzmapkgname), lzma_filepath, sizeof(lzma_filepath)) != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 错误:获取源lzma文件路径失败\n"); + return ERRCODE_FAIL; + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 源lzma文件路径:%s\n", lzma_filepath); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"decode %s to %s , ret %X \n",lzma_filepath,dialbin_filepath, ret); + // 执行解压操作 + errcode_t ret = uapi_dial_pkg_decompress(lzma_filepath, dialbin_filepath); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 解压操作完成,返回码:0x%X(%s)\n", ret, + (ret == ERRCODE_SUCC) ? "成功" : "失败"); - char *namebuf= strtok(lzmapkgname,"."); + // 关键:检查解压后bin文件是否存在及大小 + struct stat bin_info; + if (stat(dialbin_filepath, &bin_info) != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 错误:解压后bin文件不存在或无法访问(路径:%s)\n", dialbin_filepath); + ret = ERRCODE_FAIL; // 即使解压返回成功,文件不存在也视为失败 + } else { + if (bin_info.st_size <= 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 错误:解压后bin文件大小为空(%ld字节),无效文件\n", bin_info.st_size); + ret = ERRCODE_FAIL; // 大小为空视为失败 + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 解压后bin文件大小正常:%ld字节\n", bin_info.st_size); + } + } - if(ble_dial_uid>5) - { - install_Register_dial(namebuf,ble_dial_uid); + // 若解压失败,直接返回 + if (ret != ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 解压失败,终止安装流程\n"); + return ret; + } + // 注册并设置表盘 + char *namebuf = strtok(lzmapkgname, "."); + if (ble_dial_uid > 5) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 注册常规表盘:%s(ID:%d)\n", namebuf, ble_dial_uid); + install_Register_dial(namebuf, ble_dial_uid); + ble_set_dial_by_id(ble_dial_uid); + } else { + if (ble_dial_file_index == ble_dial_file_count) { + char name_str[32] = {0}; + ble_get_custom_dial(ble_dial_uid, name_str); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 自定义表盘安装完毕,注册:%s(ID:%d)\n", name_str, ble_dial_uid); + install_Register_dial(name_str, ble_dial_uid); ble_set_dial_by_id(ble_dial_uid); - - } - else - { - if(ble_dial_file_index==ble_dial_file_count) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"自定义表盘安装完毕\r\n"); - char name_str[32]={0}; - ble_get_custom_dial(ble_dial_uid,name_str); - install_Register_dial(name_str,ble_dial_uid); - ble_set_dial_by_id(ble_dial_uid); - } - + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 自定义表盘未达安装条件(当前索引:%d,总数:%d)\n", + ble_dial_file_index, ble_dial_file_count); } - - - //安装完后删除表盘 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"remove %s\r\n",lzma_filepath); - - if(0!=remove(lzma_filepath)) - return ERRCODE_FAIL; + } - if ( ret == ERRCODE_SUCC) - return ERRCODE_SUCC; - else - return ERRCODE_FAIL; - }else{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,".lzma not found\n"); - return ERRCODE_FAIL; + // 删除源lzma文件 + #if 1 + if (remove(lzma_filepath) != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 警告:删除源lzma文件失败(路径:%s),可能残留冗余文件\n", lzma_filepath); + // 此处不返回失败,仅警告,因为核心安装已完成 + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 源lzma文件已成功删除\n"); } -} + #endif + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[install_dial] 表盘安装流程全部完成,返回成功\n"); + return ERRCODE_SUCC; +} static char file_name[128]={0}; static uint32_t file_size=0; -- 2.17.1