From 6bad9c8fd262590129883c7acdd0a282be3cbb32 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=A2=81=E6=B8=85=E6=A2=A6?= <3449750381@qq.com> Date: Mon, 21 Oct 2024 11:50:55 +0000 Subject: [PATCH] Merge #1233 into sdk602patch0911 from refs/changes/1233/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Code review from 袁清梦 * refs/changes/1233/head: (15 commits squashed) - #105 5手表开启勿扰模式表盘界面会显示勿扰图标,重启后表盘勿扰图标消失(实际还是勿扰状态,下拉状态栏的勿扰图标是高亮的) - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 - 系统:删除res无用资源 - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 - 语音助手:修复对话界面的异常滑动 - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 - 表盘:同步修改表盘分区路径 - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 - 系统:增加6个功能文件夹的内存查询显示 - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 - 心率:增加弹窗脱腕(待添加) - 表盘:增加表盘数量与空间校验 - 表盘:同步ble修改(已验证) - 表盘:优化ble安装表盘的错误弹窗显示 Signed-off-by: Caisking <3449750381@qq.com> Reviewed-by: snickersun@163.com Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/1233 --- .../wearable/fd230app/CMakeLists.txt | 1 + .../heartrate/include/HeartNoteView.h | 63 +++++ .../nativeui/heartrate/src/HeartNoteView.cpp | 115 +++++++++ .../fd230app/nativeui/main/src/MainModel.cpp | 2 +- .../nativeui/set_dial/include/SetDialModel.h | 18 +- .../nativeui/set_dial/include/SetDialModelC.h | 15 ++ .../nativeui/set_dial/src/SetDialModel.cpp | 75 +++++- .../nativeui/system/include/SystemLogModel.h | 2 +- .../nativeui/system/src/SystemLogModel.cpp | 229 +++++++++--------- .../service/ble_service/blemoder/bletest.cpp | 4 + .../service/ble_service/blemoder/bletest.h | 4 +- .../service/ble_service/bleservice/bleEvent.c | 14 +- .../peripheral/utils/custom_cmd_service.c | 5 + .../drivers/peripheral/utils/custom_utils.h | 2 + 14 files changed, 422 insertions(+), 127 deletions(-) create mode 100644 code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartNoteView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartNoteView.cpp create mode 100644 code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModelC.h diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index 4e48b3fb8..85bddc1cd 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -194,6 +194,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/heartrate/src/HeartChartView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/heartrate/src/HeartChartPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/heartrate/src/HeartRateCardView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/heartrate/src/HeartNoteView.cpp #BloodCheck ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/bloodoxygen/src/BloodResultView.cpp diff --git a/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartNoteView.h b/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartNoteView.h new file mode 100644 index 000000000..667dfa935 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartNoteView.h @@ -0,0 +1,63 @@ +/*** + * @Date: 2024-04-15 10:55:58 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-07-30 11:46:23 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/include/HeartNoteView.h + */ +/*** + * @Date: 2024-04-15 10:55:58 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-05-07 18:51:13 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/include/HeartNoteView.h + */ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: bloodResult view + * Author: + * Create: 2021-08-01 + */ + +#ifndef HEART_NOTE_VIEW_H +#define HEART_NOTE_VIEW_H + +#include "View.h" +#include "BaseView.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "components/ui_label.h" +#include "components/ui_label_ext.h" +#include "components/ui_button.h" +#include "components/ui_label_button.h" +#include "components/ui_image_animator.h" +#include "components/ui_circle_progress.h" +#include "components/ui_view_group.h" + +#include "components/ui_scroll_view.h" +#include "components/ui_label_button_ext.h" +namespace OHOS { + +#define CLICK_HEART_STOP "click_heart_stop" +#define CLICK_HEART_RESTART "click_heart_restart" + + class HeartNoteView + { + public: + HeartNoteView(); + virtual ~HeartNoteView(); + UIScrollView *CreateHeartNoteView(void); + + private: + bool CrearAllView(); + // 提醒图标 + UIImageView *noteimage = nullptr; + // 按键 + UILabelButtonExt *StButton = nullptr; + UILabelButtonExt *ReButton = nullptr; + // 提醒label + UILabelExt *titleLabel = nullptr; + UILabelExt *noteLabel = nullptr; + UIScrollView *heartNoteView = nullptr; + }; +} + +#endif // 血氧主界面 \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartNoteView.cpp b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartNoteView.cpp new file mode 100644 index 000000000..d832a5e02 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartNoteView.cpp @@ -0,0 +1,115 @@ + +#include "heartrate/include/HeartNoteView.h" +#include "heartrate/include/HeartChartPresenter.h" +#include "ui_resource_string.h" +#include "uicomponents/UIComponents.h" +#include "wearable_log.h" +#include +namespace OHOS { + +static const char *ICON_PATH_NOTE = "/user/res/Blood/Error.bin"; + +HeartNoteView::HeartNoteView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HeartNoteView::HeartNoteView"); +} + +HeartNoteView::~HeartNoteView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HeartNoteView::~HeartNoteView"); + CrearAllView(); +} + +bool HeartNoteView::CrearAllView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HeartNoteView::CrearAllView"); + if (heartNoteView) { + heartNoteView->RemoveAll(); + if (noteimage) { + delete noteimage; + noteimage = nullptr; + } + if (StButton) { + delete StButton; + StButton = nullptr; + } + if (ReButton) { + delete ReButton; + ReButton = nullptr; + } + if (titleLabel) { + delete titleLabel; + titleLabel = nullptr; + } + if (noteLabel) { + delete noteLabel; + noteLabel = nullptr; + } + delete heartNoteView; + heartNoteView = nullptr; + } + return true; +} +UIScrollView *HeartNoteView::CreateHeartNoteView(void) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "CreateHeartNoteView::CreateHeartNoteView"); + /* -------------------------------------------------------------------------- + */ + if (heartNoteView == nullptr) { + heartNoteView = new UIScrollView(); + if (heartNoteView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "heartNoteView new fail"); + return nullptr; + } + } + heartNoteView->SetPosition(0, 0, 466, 466); + heartNoteView->SetScrollBlankSize(50); + heartNoteView->SetReboundSize(35); + heartNoteView->SetThrowDrag(true); + heartNoteView->SetMaxScrollDistance(1000); + heartNoteView->SetDirection(UIScrollView::VERTICAL); + // 设置拖拽监听器 + UIView::OnDragListener *dragListener = + static_cast(HeartChartPresenter::GetInstance()); + if (!dragListener) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "HeartChartPresenter::获取实例失败!"); + return nullptr; // 获取失败,返回空指针 + } + heartNoteView->SetOnDragListener(dragListener); + + /* 初始化图片 */ + InitImageView(noteimage, 193, 120, 80, 80, "image", ICON_PATH_NOTE); + + /*初始化title*/ + InitLabelExt(titleLabel, 83, 50, 300, 35, "title", STR_CHECKERROR, + DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabelExt(noteLabel, 53, 230, 360, 70, "time", STR_PWUWC, + DEFAULT_VECTOR_FONT_FILENAME, 30); + // 设置来回滚动属性 + noteLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + noteLabel->SetRollSpeed(70); + + /*初始化button*/ + InitButtonExt(StButton, 58, 320, 170, 90, CLICK_HEART_STOP, STR_STOP, 30); + StButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); // 设置按键颜色 + + UIView::OnClickListener *buttonClickst = + static_cast( + HeartChartPresenter::GetInstance()); + StButton->SetOnClickListener(buttonClickst); + + InitButtonExt(ReButton, 238, 320, 170, 90, CLICK_HEART_RESTART, STR_RECHECK, + 30); + ReButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffFF8A36); // 设置按键颜色 + UIView::OnClickListener *buttonClickre = + static_cast( + HeartChartPresenter::GetInstance()); + ReButton->SetOnClickListener(buttonClickre); + + heartNoteView->Add(noteimage); + heartNoteView->Add(titleLabel); + heartNoteView->Add(noteLabel); + heartNoteView->Add(StButton); + heartNoteView->Add(ReButton); + + return heartNoteView; +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp index ae2677280..863c5f0be 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp @@ -62,7 +62,7 @@ namespace OHOS {DIAL_CLOCK_5, "Custom_5", CUSTOM_CLOCK5_DIALPER_PATH, DEFAULT_TASK_PERIOD}, // 表盘 Id 4 }; //默认表盘 - static const char* DEFAULT_CUSTOM_DIAL_PATH = "/user/dial/obsidianrhythm.bin"; + static const char* DEFAULT_CUSTOM_DIAL_PATH = "/user/dial/res_dial/obsidianrhythm.bin"; //卡片map const CardInfo printfMap[] = { {HEART_RATE, "心率卡片"}, diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h b/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h index ef0fcfa76..beb91656a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h @@ -35,8 +35,14 @@ namespace OHOS constexpr uint16_t CUSTOM_DIAL_ID_5 = 5; #define DIAL_ID_LENGTH 2 #define DIAL_NAME_LENGTH 50 - #define DIAL_ID_PATH "user/dial/dial_id.bin" + #define DIAL_ID_PATH "user/userdata/dial_id.bin" + #define DIAL_MAX_NUM 21 + #define DIAL_CUSTOM_MAX_NUM 1 + #define DIAL_OFFLINE_DIAL_MAX_NUM 14 + #define DIAL_RES_DIAL_MAX_NUM 6 + + class SetDialModel { public: @@ -76,7 +82,11 @@ namespace OHOS bool DeleteCustomDial(uint16_t Id); void TestDialConfig(void); std::string GetSaveDir(int Id,uint8_t type); - void RegisterDial(uint16_t ID, const char *dialname,uint8_t type); + void RegisterDial(uint16_t ID, const char *dialname, uint8_t type); + + //判断是否可以继续下载表盘 + bool CheckDialDownload(uint16_t ID,uint32_t dial_size); + void CheckDialSpace(); private: void LoadAllDialFromRam(void); @@ -89,6 +99,10 @@ namespace OHOS int32_t ParseDialHeader(int type, const std::string &dialFileName, SetDialInfo &dialInfo); std::vector dialInfoList; uint16_t currentDialID = 114; // 设置表盘默认值 + + uint16_t download_DialID = 1028; + uint32_t download_dialSize = 0; + bool downloadstate = false; }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModelC.h b/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModelC.h new file mode 100644 index 000000000..bc6bf7b6c --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModelC.h @@ -0,0 +1,15 @@ + +#ifndef SET_DIAL_MODEL_C_H +#define SET_DIAL_MODEL_C_H + +#ifdef __cplusplus +extern "C" { +#endif + +void check_dial_space(void); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file 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 a6cc799c5..850dfffab 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 @@ -1,13 +1,15 @@ - -#include "SetDialModel.h" +#include "set_dial/include/SetDialModel.h" #include "DialBinParser.h" #include "MainModel.h" #include "NativeAbility.h" #include "clock/include/MainClockView.h" +#include "custom_runtime.h" #include "custom_utils.h" #include "dirent.h" #include "kv_store.h" #include "securec.h" +#include "set_dial/include/SetDialModelC.h" +#include "system/include/SystemLogModel.h" #include "wearable_log.h" #include #include @@ -20,6 +22,10 @@ #include #include #include + +extern "C" { +void check_dial_space() { OHOS::SetDialModel::GetInstance().CheckDialSpace(); } +} namespace OHOS { // 表盘map[Id--dialname] 前5个ID固定 @@ -35,7 +41,7 @@ std::unordered_map registeredDials{ /* TODO:增加表盘 - {DEFAULT_DIAL_ID_3, "smart_payment"}, // 智能支付表盘 + {DEFAULT_DIAL_ID_3, "dawn_insight"}, // 晨曦智影 {MAX_DEFAULT_DIAL_ID, "kumi_point"}, // kumi指针表盘 */ @@ -101,8 +107,8 @@ bool SetDialModel::readDialfile() { } SetDialModel::SetDialModel() { - readDialfile(); // 读取表盘map配置文件 LoadAllDial(); // 更新表盘个数 当前表盘 + readDialfile(); // 读取表盘map配置文件 char idBuffer[10]; // 读取表盘Id配置文件 int len = UtilsGetValue("dial_id", idBuffer, sizeof(idBuffer)); if (len >= 0) { @@ -184,7 +190,7 @@ uint16_t SetDialModel::GetCurrentDialID() { return id; } /* 获取所有表盘Id 每个表盘Id 2个字节 拼接为字符串 */ -int SetDialModel::GetAllDialIDs(char *allidStr,uint16_t MAX_LEN) { +int SetDialModel::GetAllDialIDs(char *allidStr, uint16_t MAX_LEN) { std::string allIDs; int length = 0; for (const auto &entry : registeredDials) { @@ -192,8 +198,8 @@ int SetDialModel::GetAllDialIDs(char *allidStr,uint16_t MAX_LEN) { if (id <= 5) { id--; } - if(lengthdialName); } +//判断是否可以继续下载表盘 +void SetDialModel::CheckDialSpace() { + downloadstate = true; + //安装离线表盘 + if (download_DialID > 5) { + //离线表盘 判断当前离线表盘个数 + uint8_t offlinedial_num = + DIAL_OFFLINE_DIAL_MAX_NUM - + (GetDialCount() - DIAL_CUSTOM_MAX_NUM - DIAL_RES_DIAL_MAX_NUM); + if (offlinedial_num <= 0) { + //离线表盘个数已到上限 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "CheckDialSpace: Offline dial count %d", offlinedial_num); + downloadstate = false; + return; + } else { + //判断offlinedial文件夹内存是否可以继续存储 + downloadstate = SystemLogModel::GetInstance()->canSyncFile( + TOTAL_DIAL_SPACE_PATH, TOTAL_DIAL_SPACE, download_dialSize); + //离线表盘 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CheckDialSpace: Offline dial %d", + downloadstate); + return; + } + } else { + //安装自定义表盘 + downloadstate = SystemLogModel::GetInstance()->canSyncFile( + TOTAL_CUSTOM_DAIL_SPACE_PATH, TOTAL_CUSTOM_DAIL_SPACE, + download_dialSize); + //自定义表盘 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CheckDialSpace: Custom dial %d", + downloadstate); + } +} + +bool SetDialModel::CheckDialDownload(uint16_t ID, uint32_t dial_size) { + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CheckDialDownload: %d %d", ID, + dial_size); + + download_DialID = ID; + download_dialSize = dial_size; + + // do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_CHECK_DIAL_SPACE, nullptr,0); + CheckDialSpace(); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CheckDialDownload: %d", + downloadstate); + return downloadstate; +} + } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModel.h b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModel.h index b4849c483..a8050a144 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModel.h @@ -16,7 +16,7 @@ #define TOTAL_RING_SPACE (2 * 1024 * 1024) // 2M #define TOTAL_RING_SPACE_PATH "/user/musci/ring" -#define TOTAL_DIAL_SPACE (27 * 1024 * 1024) // 27M +#define TOTAL_DIAL_SPACE (24 * 1024 * 1024) // 24M #define TOTAL_DIAL_SPACE_PATH "/user/dial/offline_dial" #define TOTAL_RES_DIAL_SPACE (7 * 1024 * 1024) // 7M diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLogModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLogModel.cpp index f3924d599..d6eeba4b5 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLogModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLogModel.cpp @@ -12,23 +12,23 @@ #include #include #include +#include #include #include #include #include #include +#include #include +#include #include #include #include #include -#include -#include -#include -#define SYSTEM_LOG_FILE_PATH "/system/system_log.txt" -#define SYSTEM_LOG_FILE_PATH_NEXTDAY "/system/system_log_nextday.txt" -#define SYSTEM_LOG_FILE_PATH_POPUP_WINDOWS "/system/popup_windows_log.txt" +#define SYSTEM_LOG_FILE_PATH "/user/system/system_log.txt" +#define SYSTEM_LOG_FILE_PATH_NEXTDAY "/user/system/system_log_nextday.txt" +#define SYSTEM_LOG_FILE_PATH_POPUP_WINDOWS "/user/system/popup_windows_log.txt" extern "C" { // 通用日志记录功能 @@ -142,6 +142,40 @@ const std::deque &SystemLogModel::getLogData() const { // 获取日志大小 size_t SystemLogModel::getLogSize() const { return logData.size(); } +long long SystemLogModel::getFolderSize(const char *folderPath) { + DIR *dir; + struct dirent *entry; + struct stat fileStat; + long long totalSize = 0; + + dir = opendir(folderPath); + if (dir == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error opening directory"); + return 0; + } + + while ((entry = readdir(dir)) != NULL) { + char filePath[1024]; + snprintf(filePath, sizeof(filePath), "%s/%s", folderPath, entry->d_name); + + if (stat(filePath, &fileStat) == -1) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error getting file status"); + continue; + } + + if (S_ISDIR(fileStat.st_mode)) { + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) + continue; + totalSize += getFolderSize(filePath); + } else { + totalSize += fileStat.st_size; + } + } + + closedir(dir); + return totalSize; +} + //获取系统内存 /* [FS INFO]total size=12416KB used size=8114KB free size=4302KB @@ -154,17 +188,11 @@ size_t SystemLogModel::getLogSize() const { return logData.size(); } */ std::string SystemLogModel::get_system_mem_info() { struct statfs file_buf = {0}; - std::stringstream result; // 使用 stringstream 来构建返回的字符串 - const std::vector volume_names = {"/system/", "/update/", - "/music/", "/user/"}; - - for (const auto &volume : volume_names) { - // 获取文件系统状态 - if (statfs(volume.c_str(), &file_buf) != 0) { - result << "Error retrieving info for " << volume << std::endl; - continue; - } - + std::stringstream result; + std::string system_volume_name = "/user/"; + if (statfs(system_volume_name.c_str(), &file_buf) != 0) { + result << "Error retrieving info for " << system_volume_name << std::endl; + } else { // 计算总大小、已用大小和自由空间 uint64_t total_size = static_cast(file_buf.f_blocks) * file_buf.f_bsize; @@ -173,63 +201,47 @@ std::string SystemLogModel::get_system_mem_info() { uint64_t used_size = total_size - free_size; // 按照所需格式输出 - result << "[" << volume << "]" << std::endl; - result << "Total size=" << total_size / 1024 << "KB " << std::endl; - result << "Used size=" << used_size / 1024 << "KB " << std::endl; - result << "Free size=" << free_size / 1024 << "KB" << std::endl; + result << "[" << system_volume_name << "]" << std::endl; + result << "Total size = " << total_size / 1024 << " KB" << std::endl; + result << "Used size = " << used_size / 1024 << " KB" << std::endl; + result << "Free size = " << free_size / 1024 << " KB" << std::endl; + result << "====================" << std::endl; // 分隔线 } - // 返回所有分区的自由空间信息,如果没有信息,则返回说明信息 - return result.str().empty() ? "No volumes found or accessible." - : result.str(); -} - - - -long long SystemLogModel::getFolderSize(const char* folderPath) { - DIR* dir; - struct dirent* entry; - struct stat fileStat; - long long totalSize = 0; - - dir = opendir(folderPath); - if (dir == NULL) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error opening directory"); - return 0; - } + std::vector volume_names = { + "/user/dial/", "/user/music/", "/user/update/", + "/user/res/", "/user/system/", "/user/userdata/", + }; - while ((entry = readdir(dir))!= NULL) { - char filePath[1024]; - snprintf(filePath, sizeof(filePath), "%s/%s", folderPath, entry->d_name); - - if (stat(filePath, &fileStat) == -1) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error getting file status"); - continue; - } - - if (S_ISDIR(fileStat.st_mode)) { - if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) - continue; - totalSize += getFolderSize(filePath); - } else { - totalSize += fileStat.st_size; - } + // 遍历每个目录,获取文件系统状态 + for (const auto &volume_name : volume_names) { + // 获取文件系统状态 + uint64_t total_size = getFolderSize(volume_name.c_str()); + if (total_size == 0) { + result << "Error retrieving info for " << volume_name << std::endl; + } else { + // 计算总大小 + result << "[" << volume_name << "]" << std::endl; + result << "Total size = " << total_size / 1024 << " KB" << std::endl; + result << "====================" << std::endl; // 分隔线 } + } - closedir(dir); - return totalSize; + // 如果没有信息,则返回说明信息 + return result.str().empty() ? "No volumes found or accessible." + : result.str(); } // 检查是否可以同步文件 -bool SystemLogModel::canSyncFile(std::string path,uint32_t path_max_size,uint32_t download_size) -{ - // 获取文件夹的大小 - long long usedSpace = getFolderSize(path.c_str()); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "usedSpace = %lld",usedSpace); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "path_max_size = %lld",path_max_size); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "download_size = %lld",download_size); - - return (usedSpace + download_size) <= path_max_size; +bool SystemLogModel::canSyncFile(std::string path, uint32_t path_max_size, + uint32_t download_size) { + // 获取文件夹的大小 + long long usedSpace = getFolderSize(path.c_str()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "usedSpace = %lld", usedSpace); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "path_max_size = %lld", path_max_size); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "download_size = %lld", download_size); + + return (usedSpace + download_size) <= path_max_size; } // nextday相关 bool SystemLogModel::save_nextday_log(uint32_t timestamp) { @@ -282,69 +294,68 @@ size_t SystemLogModel::get_nextday_log_size() const { } // 保存popup_windows日志 -bool SystemLogModel::save_popup_windows_log(popup_windows_log_data data) -{ - // 保存新日志 - popup_windows_log.push_back(data); - - // 将日志写入文件 - std::ofstream outFile(SYSTEM_LOG_FILE_PATH_POPUP_WINDOWS, std::ios::app); - if (!outFile) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to open log file for writing"); - return false; // 文件打开失败 - } +bool SystemLogModel::save_popup_windows_log(popup_windows_log_data data) { + // 保存新日志 + popup_windows_log.push_back(data); + + // 将日志写入文件 + std::ofstream outFile(SYSTEM_LOG_FILE_PATH_POPUP_WINDOWS, std::ios::app); + if (!outFile) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "Failed to open log file for writing"); + return false; // 文件打开失败 + } - // 将结构体中的数据转换为字符串格式写入文件 - outFile << static_cast(data.type) << " " << data.timestamp << std::endl; - outFile.close(); - return true; + // 将结构体中的数据转换为字符串格式写入文件 + outFile << static_cast(data.type) << " " << data.timestamp << std::endl; + outFile.close(); + return true; } -bool SystemLogModel::load_popup_windows_log() -{ - std::ifstream inFile(SYSTEM_LOG_FILE_PATH_POPUP_WINDOWS); - if (!inFile) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to open log file for reading"); - return false; // 无法打开文件 - } +bool SystemLogModel::load_popup_windows_log() { + std::ifstream inFile(SYSTEM_LOG_FILE_PATH_POPUP_WINDOWS); + if (!inFile) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "Failed to open log file for reading"); + return false; // 无法打开文件 + } - std::string line; - while (std::getline(inFile, line)) { - std::istringstream ss(line); - popup_windows_log_data data; - int typeInt; - if (ss >> typeInt >> data.timestamp) { - data.type = static_cast(typeInt); - popup_windows_log.push_back(data); - } + std::string line; + while (std::getline(inFile, line)) { + std::istringstream ss(line); + popup_windows_log_data data; + int typeInt; + if (ss >> typeInt >> data.timestamp) { + data.type = static_cast(typeInt); + popup_windows_log.push_back(data); } + } - inFile.close(); - return true; + inFile.close(); + return true; } // 获取popup_windows日志记录(常量引用) -const std::deque &SystemLogModel::get_popup_windows_log() const -{ +const std::deque & +SystemLogModel::get_popup_windows_log() const { return popup_windows_log; } // 获取日志大小 -size_t SystemLogModel::get_popup_windows_log_size() const -{ +size_t SystemLogModel::get_popup_windows_log_size() const { return popup_windows_log.size(); } -void SystemLogModel::clear_popup_windows_log() -{ - // 清空当前的日志 +void SystemLogModel::clear_popup_windows_log() { + // 清空当前的日志 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clear_popup_windows_log"); popup_windows_log.clear(); - + std::ofstream outFile(SYSTEM_LOG_FILE_PATH_POPUP_WINDOWS, std::ios::trunc); if (!outFile) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to open log file for writing"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "Failed to open log file for writing"); return; } - outFile<<""; + outFile << ""; outFile.close(); } } // namespace OHOS diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp index c58611b31..d72f6c3a2 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -918,6 +918,10 @@ void get_sedent_param( msg_sedent_set_param_info_t * data) return; } +bool check_dial_freespace(uint16_t id,uint32_t dial_size) { + return OHOS::SetDialModel::GetInstance().CheckDialDownload(id,dial_size); +} + void ble_get_dial_path(char * buf,uint16_t id) { char *path= (char*)OHOS::SetDialModel::GetInstance().GetSaveDir(id,0).c_str(); 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 f20fafe1b..e4e41d34a 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h @@ -247,7 +247,9 @@ bool dial_file_save(void); void ble_save_dial_custom(msg_recv_custom_dial_info_t *data); -void ble_get_custom_dial(uint16_t id,char *buf); +void ble_get_custom_dial(uint16_t id, char *buf); + +bool check_dial_freespace(uint16_t id,uint32_t dial_size); //////////////////////久坐提醒//////////////////////////// void set_sedent_param( msg_sedent_set_param_info_t * data); 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 6563c350e..7330aad0d 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -7284,8 +7284,11 @@ errcode_t decode_single_dial_info(ble_read_data *buffer_handle) ble_dial_uid = dialinfo.dial_uid; // if(ble_dial_uid<=4) // ble_dial_uid++; - + if (check_dial_freespace(ble_dial_uid, file_size) == false) + { + return ERRCODE_FAIL; + } buffer_handle->file_recv_stat.file_name = filename; buffer_handle->file_recv_stat.file_size = file_size; @@ -7760,10 +7763,10 @@ void type2AE0Data(ble_read_data *buffer_handle) if (decode_single_dial_info(buffer_handle) == ERRCODE_SUCC) { ble_reply_cmd(SINGLE_DIAL_FILE_RECV_CMD,1); - - }else{ + } else { + TRANSMIT_DATA=TRANS_DIAL_FAIL; + CustomEventPublish(TOPIC_EVENT_BLE_TRANSMIT,&TRANSMIT_DATA,1); ble_reply_cmd(SINGLE_DIAL_FILE_RECV_CMD,2); - } break; case EPO_DATA_RECV_CMD: @@ -7857,7 +7860,8 @@ void type2AE6Data(ble_read_data *buffer_handle,uint8_t *cmd_buf ,uint8_t *data,u { ble_reply_cmd(DIAL_SINGEL_FILE_CMD,1); - }else{ + } else { + ble_reply_cmd(DIAL_SINGEL_FILE_CMD,2); } diff --git a/code/sdk/drivers/peripheral/utils/custom_cmd_service.c b/code/sdk/drivers/peripheral/utils/custom_cmd_service.c index 22885b27a..4811b315c 100644 --- a/code/sdk/drivers/peripheral/utils/custom_cmd_service.c +++ b/code/sdk/drivers/peripheral/utils/custom_cmd_service.c @@ -40,9 +40,11 @@ #include "bletest.h" #include "safemodemanager/include/SafeModeManagerModelC.h" +#include "set_dial/include/SetDialModelC.h" #include "alarmclocktimerconfig/include/AlarmClockTimerConfig.h" + typedef struct { uint8_t cmd; @@ -304,6 +306,9 @@ static void custom_cmd_service_check_task(void const *arg) case CUSTOM_CMD_MSG_BLE_ADV_CHECK: Check_ble_adv_status(); break; + case CUSTOM_CMD_MSG_CHECK_DIAL_SPACE: + check_dial_space(); + break; default: PRINT("Unknown CUSTOM_CMD_MSG cmd 0x%02X \r\n", mail.cmd); break; diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index b532c7c3d..d2c495a6c 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -224,6 +224,8 @@ uint32_t uapi_calendar_store_date(void); #define CUSTOM_CMD_MSG_BLE_ADV_CHECK 0x11 +#define CUSTOM_CMD_MSG_CHECK_DIAL_SPACE 0x12 + typedef enum { BR_HFP_CONNECT=1, BR_HFP_DISCONNECT, -- 2.17.1