From d4f4d8f22491b8938bb2d603311667e7d73ba4dc Mon Sep 17 00:00:00 2001 From: Caisking Date: Mon, 8 Sep 2025 16:39:37 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E6=94=B9650dial=E4=B8=8B=E8=BD=BD?= =?utf8?q?=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/set_dial/src/SetDialModel.cpp | 254 ++++++------------ .../set_dial/src/SetDialPresenter.cpp | 7 +- .../nativeui/system/include/SystemLogModel.h | 2 +- 3 files changed, 88 insertions(+), 175 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 0c23170ff..ec89ed794 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 @@ -1,20 +1,21 @@ #include "set_dial/include/SetDialModel.h" #include "DialBinParser.h" -#include "main/include/MainModel.h" #include "NativeAbility.h" +#include "main/include/MainModel.h" #ifdef SUPPORT_BLE_SERVICE #include "bleEvent.h" #include "bleInstruct.h" +#include "bleService.h" #endif #include "clock/include/MainClockView.h" #include "custom_runtime.h" #include "custom_utils.h" #include "dirent.h" +#include "graphic_service.h" #include "kv_store.h" #include "securec.h" #include "set_dial/include/SetDialModelC.h" -// #include "system/include/SystemLogModel.h" -#include "graphic_service.h" +#include "system/include/SystemLogModel.h" #include "wearable_log.h" #include #include @@ -165,10 +166,6 @@ void SetDialModel::RegisterDial(uint16_t ID, const char *dialname) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RegisterDial %d %s is ok!", ID, dialname); - - // 手表加载map不需要遍历 - // LoadAllDial(); - // saveDialfile(); } /* 注册表盘map_ble*/ @@ -212,6 +209,7 @@ uint16_t SetDialModel::GetDialIdFromName(const std::string &dialName) { } return 0; // 如果未找到对应的表盘名称,返回0或者其他适当的默认值 } + /*通过表盘Id查询名称*/ std::string SetDialModel::GetdialPath(int Id) { //判断Id是否在map中 @@ -271,110 +269,11 @@ bool SetDialModel::IsDialInstalled(uint16_t ID) { } /*删除自定义表盘文件*/ bool SetDialModel::DeleteCustomDial(uint16_t Id) { -#if 0 - // 删除配置文件 - std::string filename = GetSaveDir(Id) + "/" + std::to_string(Id) + ".bin"; - if (!uapi_delete_files(filename.c_str())) { - WEARABLE_LOGE( - WEARABLE_LOG_MODULE_APP, - "DeleteCustomDial: Failed to delete the dial configuration file: %s", - filename.c_str()); - return false; - } - - // 删除资源文件 - switch (Id) { - case CUSTOM_DIAL_ID_1: - if (!uapi_delete_files(CUSTOM_CLOCK1_DIALPER_PATH)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "DeleteCustomDial: Failed to delete dial percentage file " - "for ID 1: %s", - CUSTOM_CLOCK1_DIALPER_PATH); - return false; - } - if (!uapi_delete_files(CUSTOM_CLOCK1_DIALBACK_PATH)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "DeleteCustomDial: Failed to delete dial background file " - "for ID 1: %s", - CUSTOM_CLOCK1_DIALBACK_PATH); - return false; - } - break; - - case CUSTOM_DIAL_ID_2: - if (!uapi_delete_files(CUSTOM_CLOCK2_DIALPER_PATH)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "DeleteCustomDial: Failed to delete dial percentage file " - "for ID 2: %s", - CUSTOM_CLOCK2_DIALPER_PATH); - return false; - } - if (!uapi_delete_files(CUSTOM_CLOCK2_DIALBACK_PATH)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "DeleteCustomDial: Failed to delete dial background file " - "for ID 2: %s", - CUSTOM_CLOCK2_DIALBACK_PATH); - return false; - } - break; - - case CUSTOM_DIAL_ID_3: - if (!uapi_delete_files(CUSTOM_CLOCK3_DIALPER_PATH)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "DeleteCustomDial: Failed to delete dial percentage file " - "for ID 3: %s", - CUSTOM_CLOCK3_DIALPER_PATH); - return false; - } - if (!uapi_delete_files(CUSTOM_CLOCK3_DIALBACK_PATH)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "DeleteCustomDial: Failed to delete dial background file " - "for ID 3: %s", - CUSTOM_CLOCK3_DIALBACK_PATH); - return false; - } - break; - - case CUSTOM_DIAL_ID_4: - if (!uapi_delete_files(CUSTOM_CLOCK4_DIALPER_PATH)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "DeleteCustomDial: Failed to delete dial percentage file " - "for ID 4: %s", - CUSTOM_CLOCK4_DIALPER_PATH); - return false; - } - if (!uapi_delete_files(CUSTOM_CLOCK4_DIALBACK_PATH)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "DeleteCustomDial: Failed to delete dial background file " - "for ID 4: %s", - CUSTOM_CLOCK4_DIALBACK_PATH); - return false; - } - break; - - case CUSTOM_DIAL_ID_5: - if (!uapi_delete_files(CUSTOM_CLOCK5_DIALPER_PATH)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "DeleteCustomDial: Failed to delete dial percentage file " - "for ID 5: %s", - CUSTOM_CLOCK5_DIALPER_PATH); - return false; - } - if (!uapi_delete_files(CUSTOM_CLOCK5_DIALBACK_PATH)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "DeleteCustomDial: Failed to delete dial background file " - "for ID 5: %s", - CUSTOM_CLOCK5_DIALBACK_PATH); - return false; - } - break; - - default: + if (Id < 0 || Id > 5) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "DeleteCustomDial: Invalid dial ID: %d", Id); - return false; // ID 不合法 + "DeleteCustomDial: Id is not valid %d", Id); + return false; } -#endif std::string dirpath = GetSaveDir(Id) + "/"; if (uapi_delete_folder(dirpath.c_str()) == -1) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, @@ -470,10 +369,12 @@ void SetDialModel::UpdateDialSetting(uint16_t ID) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdateDialSetting: Current dial %d cannot be updated %d", currentDialID, ID); - // reply_app_send_switchDialCmd(false); +#ifdef SUPPORT_BLE_SERVICE + reply_app_send_switchDialCmd(false); +#endif return; } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UpdateDialSetting: ID %d", ID); + WEARABLE_LOGE(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, @@ -498,18 +399,24 @@ void SetDialModel::UpdateDialSetting(uint16_t ID) { if (uapi_dev_runtime_get_train_status() != 1) { NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); } - // svr_ble_read_data_value_updata_noyify(); // app切换表盘增加id更新 - // reply_app_send_switchDialCmd(true); +#ifdef SUPPORT_BLE_SERVICE + svr_ble_read_data_value_updata_noyify(); // app切换表盘增加id更新 + reply_app_send_switchDialCmd(true); +#endif return; // 更新成功后直接返回 } } - //没有在列表找到名称 - // reply_app_send_switchDialCmd(false); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, +//没有在列表找到名称 +#ifdef SUPPORT_BLE_SERVICE + reply_app_send_switchDialCmd(false); +#endif + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dialInfoList name %s is already registered", dialname.c_str()); } else { - // reply_app_send_switchDialCmd(false); +#ifdef SUPPORT_BLE_SERVICE + reply_app_send_switchDialCmd(false); +#endif WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetDialModel UpdateDialSetting: Cannot find dial %d", ID); } @@ -537,9 +444,10 @@ void SetDialModel::LoadAllDial() { GetAllDialIDs(dialId, 128); PrintRegisteredDials(registeredDials); - std::sort(aodDialInfoList.begin() + aodSize, - aodDialInfoList.end(), - [](const SetDialInfo &f, const SetDialInfo &n) { return f.dialName < n.dialName; }); + std::sort(aodDialInfoList.begin() + aodSize, aodDialInfoList.end(), + [](const SetDialInfo &f, const SetDialInfo &n) { + return f.dialName < n.dialName; + }); } /*加载离线表盘*/ void SetDialModel::LoadAllDialFromFs() { @@ -555,9 +463,9 @@ void SetDialModel::LoadAllDialFromFs() { int ret = ParseDialHeader(DOWNLOADDIAL, direntp->d_name, dialInfo); if (ret == 0) { if (dialInfo.capability == DIAL_DISPLAY_CAPABILITY_NORMAL_ONLY) { - dialInfoList.push_back(dialInfo); + dialInfoList.push_back(dialInfo); } else if (dialInfo.capability == - DIAL_DISPLAY_CAPABILITY_AMBITIENT_ONLY) { + DIAL_DISPLAY_CAPABILITY_AMBITIENT_ONLY) { aodDialInfoList.push_back(dialInfo); } else { dialInfoList.push_back(dialInfo); @@ -567,6 +475,8 @@ void SetDialModel::LoadAllDialFromFs() { } } } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "离线表盘数量: downloadnum %d", + downloadnum); // 关闭目录 closedir(dirp); return; @@ -621,7 +531,7 @@ void SetDialModel::LoadAllDialFromDefult(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Adding dial %s", fullDialName.c_str()); if (dialInfo.capability == DIAL_DISPLAY_CAPABILITY_NORMAL_ONLY) { - dialInfoList.push_back(dialInfo); + dialInfoList.push_back(dialInfo); } else if (dialInfo.capability == DIAL_DISPLAY_CAPABILITY_AMBITIENT_ONLY) { aodDialInfoList.push_back(dialInfo); @@ -660,7 +570,8 @@ int32_t SetDialModel::ParseDialHeader(int type, const std::string &dialFileName, } DialPreviewInfo preInfo{0}; bool ret = false; - ret = DialBinParserManager::GetInstance()->GetDialPreviewInfo(dialFullName, fp, &preInfo); + ret = DialBinParserManager::GetInstance()->GetDialPreviewInfo(dialFullName, + fp, &preInfo); if (!ret) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetDialPreviewInfo %s fail", dialFullName.c_str()); @@ -743,21 +654,20 @@ size_t SetDialModel::GetDialCount(void) { std::vector &SetDialModel::GetDialInfo(void) { return dialInfoList; } -std::vector& SetDialModel::GetAmbientDialInfo(void) -{ +std::vector &SetDialModel::GetAmbientDialInfo(void) { return aodDialInfoList; } -void SetDialModel::ClearDialInfo(void) -{ - for (auto iter : dialInfoList) { - if (iter.dialFlag) { - ImageCacheManager::GetInstance().UnloadOneInMultiRes(iter.resId, iter.dialFullName); - } else { - ImageCacheManager::GetInstance().UnloadSingleRes(iter.imageFullName); - } +void SetDialModel::ClearDialInfo(void) { + for (auto iter : dialInfoList) { + if (iter.dialFlag) { + ImageCacheManager::GetInstance().UnloadOneInMultiRes(iter.resId, + iter.dialFullName); + } else { + ImageCacheManager::GetInstance().UnloadSingleRes(iter.imageFullName); } - dialInfoList.clear(); - aodDialInfoList.clear(); + } + dialInfoList.clear(); + aodDialInfoList.clear(); } uint8_t SetDialModel::GetPageIndex(void) { @@ -1024,40 +934,40 @@ std::string SetDialModel::GetCustomName(int Id) { //判断是否可以继续下载表盘 void SetDialModel::CheckDialSpace() { - // downloadstate = true; - // //安装离线表盘 - // if (download_DialID > 5) { - // //离线表盘 判断当前离线表盘个数 - // uint8_t offlinedial_num = - // DIAL_OFFLINE_DIAL_MAX_NUM - downloadnum; //最多下载3个 - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - // "CheckDialSpace: Offline dial count %d", offlinedial_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); - // } + downloadstate = true; + //安装离线表盘 + if (download_DialID > 5) { + //离线表盘 判断当前离线表盘个数 + uint8_t offlinedial_num = + DIAL_OFFLINE_DIAL_MAX_NUM - downloadnum; //最多下载3个 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "CheckDialSpace: Offline dial count %d", offlinedial_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, + "离线表盘 is %d:total space is %d download_dialSize is %d", + downloadstate, TOTAL_DIAL_SPACE, download_dialSize); + return; + } + } else { + //安装自定义表盘 + downloadstate = SystemLogModel::GetInstance()->canSyncFile( + TOTAL_CUSTOM_DAIL_SPACE_PATH, TOTAL_CUSTOM_DAIL_SPACE, + download_dialSize); + //自定义表盘 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "自定义表盘 is %d:total space is %d download_dialSize is %d", + downloadstate, TOTAL_CUSTOM_DAIL_SPACE, download_dialSize); + } } bool SetDialModel::CheckDialDownload(uint16_t ID, uint32_t dial_size) { @@ -1113,11 +1023,11 @@ void ble_save_dial_custom_(msg_recv_custom_dial_info_t *data) { } void ble_set_dial_by_id__(uint16_t id) { - // printf("ble_set_dial_by_id_ %d\n",id); + printf("ble_set_dial_by_id_ %d\n", id); OHOS::SetDialModel::GetInstance().UpdateDialSetting(id); } void ble_set_dial_by_id_(uint16_t id) { - // printf("ble_set_dial_by_id %d\n",id); + printf("ble_set_dial_by_id %d\n", id); GraphicService::GetInstance()->PostGraphicEvent( std::bind(ble_set_dial_by_id__, id)); } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_dial/src/SetDialPresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_dial/src/SetDialPresenter.cpp index c15694e87..637580dc1 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_dial/src/SetDialPresenter.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_dial/src/SetDialPresenter.cpp @@ -21,6 +21,7 @@ #ifdef SUPPORT_BLE_SERVICE #include "bleEvent.h" #include "bleInstruct.h" +#include "bleService.h" #endif #include "NativeRegisterManager.h" @@ -71,8 +72,10 @@ namespace OHOS OnClickAction(); //具有延迟 更新表盘 - // svr_ble_read_data_value_updata_noyify(); - // Watch_SendDial_ToAppCmd(); + #ifdef SUPPORT_BLE_SERVICE + svr_ble_read_data_value_updata_noyify(); + Watch_SendDial_ToAppCmd(); + #endif return true; } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/system/include/SystemLogModel.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/system/include/SystemLogModel.h index 0368b7faa..b4dec424c 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/system/include/SystemLogModel.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/system/include/SystemLogModel.h @@ -22,7 +22,7 @@ #define TOTAL_RES_DIAL_SPACE (5 * 1024 * 1024) // 5M #define TOTAL_RES_DIAL_SPACE_PATH "/user/dial/res_dial" -#define TOTAL_CUSTOM_DAIL_SPACE (1 * 1024 * 1024) // 1M +#define TOTAL_CUSTOM_DAIL_SPACE (2 * 1024 * 1024) // 2M #define TOTAL_CUSTOM_DAIL_SPACE_PATH "/user/dial/custom_dial" #define TOTAL_SYSTEM_SPACE (5 * 1024 * 1024) // 5M -- 2.17.1