表盘:增加表盘数量与空间校验 1233/2
authorCaisking <3449750381@qq.com>
Mon, 21 Oct 2024 09:28:25 +0000 (17:28 +0800)
committerCaisking <3449750381@qq.com>
Mon, 21 Oct 2024 09:28:25 +0000 (17:28 +0800)
code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h
code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModelC.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp
code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModel.h
code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLogModel.cpp
code/sdk/drivers/peripheral/utils/custom_cmd_service.c
code/sdk/drivers/peripheral/utils/custom_utils.h

index ef0fcfa..f3e544f 100644 (file)
@@ -37,6 +37,12 @@ namespace OHOS
     #define DIAL_NAME_LENGTH 50
     #define DIAL_ID_PATH "user/dial/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<SetDialInfo> 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 (file)
index 0000000..bc6bf7b
--- /dev/null
@@ -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
index a6cc799..bf8af65 100644 (file)
@@ -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 <algorithm>
 #include <array>
 #include <string>
 #include <sys/stat.h>
 #include <unistd.h>
+
+extern "C" {
+void check_dial_space() {
+  OHOS::SetDialModel::GetInstance().CheckDialSpace();
+}
+}
 namespace OHOS {
 
 // 表盘map[Id--dialname] 前5个ID固定
@@ -35,7 +43,7 @@ std::unordered_map<uint16_t, std::string> registeredDials{
 
     /*
       TODO:增加表盘
-      {DEFAULT_DIAL_ID_3, "smart_payment"}, // 智能支付表盘
+      {DEFAULT_DIAL_ID_3, "dawn_insight"}, // 晨曦智影
       {MAX_DEFAULT_DIAL_ID, "kumi_point"},  // kumi指针表盘
     */
 
@@ -184,7 +192,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 +200,8 @@ int SetDialModel::GetAllDialIDs(char *allidStr,uint16_t MAX_LEN) {
     if (id <= 5) {
       id--;
     }
-    if(length<MAX_LEN)
-    memcpy_s(allidStr + length, 512, &id, 2);
+    if (length < MAX_LEN)
+      memcpy_s(allidStr + length, 512, &id, 2);
     length += 2;
   }
 
@@ -452,7 +460,7 @@ void SetDialModel::LoadAllDial() {
 
   // 表盘Id以及表盘map打印
   char dialId[128];
-  GetAllDialIDs(dialId,128);
+  GetAllDialIDs(dialId, 128);
   PrintRegisteredDials(registeredDials);
 }
 /*加载离线表盘*/
@@ -858,4 +866,45 @@ std::string SetDialModel::GetCustomName(int Id) {
   return (info->dialName);
 }
 
+//判断是否可以继续下载表盘
+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);
+      return;
+    }
+  } else {
+    //安装自定义表盘
+    downloadstate = SystemLogModel::GetInstance()->canSyncFile(
+        TOTAL_CUSTOM_DAIL_SPACE_PATH, TOTAL_CUSTOM_DAIL_SPACE,
+        download_dialSize);
+  }
+}
+
+bool SetDialModel::CheckDialDownload(uint16_t ID, uint32_t dial_size) {
+
+  download_DialID = ID;
+  download_dialSize = dial_size;
+
+  do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_CHECK_DIAL_SPACE, nullptr, 0);
+
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CheckDialDownload: %d",
+                downloadstate);
+  return downloadstate;
+}
+
 } // namespace OHOS
index b4849c4..a8050a1 100644 (file)
@@ -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
index 8b1718a..d6eeba4 100644 (file)
@@ -216,7 +216,7 @@ std::string SystemLogModel::get_system_mem_info() {
   // 遍历每个目录,获取文件系统状态
   for (const auto &volume_name : volume_names) {
     // 获取文件系统状态
-    uint64_t total_size =getFolderSize(volume_name.c_str());
+    uint64_t total_size = getFolderSize(volume_name.c_str());
     if (total_size == 0) {
       result << "Error retrieving info for " << volume_name << std::endl;
     } else {
index 22885b2..4811b31 100644 (file)
 #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;
index b532c7c..d2c495a 100644 (file)
@@ -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,