内存分配管理定义和文件同步接口判断实现(待验证) 1225/2 1225/head
authorluozheng <1732036298@qq.com>
Sun, 20 Oct 2024 10:55:37 +0000 (18:55 +0800)
committerluozheng <1732036298@qq.com>
Sun, 20 Oct 2024 10:55:37 +0000 (18:55 +0800)
code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModelC.h
code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp
code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModel.h
code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLogModel.cpp

index af325e9..955de68 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-08-17 14:06:51
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-10-14 11:02:57
+ * @LastEditTime: 2024-10-20 18:19:49
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModelC.h
  */
 
@@ -18,6 +18,7 @@ extern "C"
 #include <stdint.h>
     void stopPlayingMusic(void);
     void custom_setUpListCase(void);
+    bool  canSyncMusic(uint32_t songSize);
    
 #ifdef __cplusplus
 #if __cplusplus
index 62a81ba..1a6a266 100644 (file)
@@ -22,6 +22,7 @@
 #include "settings/include/SettingModel.h"
 #include "bluetooth/include/BluetoothHeadsetEvent.h"
 #include <bts_a2dp_sink.h>
+#include "system/include/SystemLogModel.h"
 namespace OHOS {
 
 static constexpr int VOLUME_MAXIMUM = 100;
@@ -1172,6 +1173,12 @@ extern "C"
         OHOS::PlayersModel::GetInstance()->PlayerInit();
     }
 
+    // 检查是否可以同步音乐
+    bool canSyncMusic(uint32_t songSize) 
+    {
+        return OHOS::SystemLogModel::GetInstance()->canSyncFile(APP_MUSIC_PATH,TOTAL_MUSIC_SPACE,songSize);
+    }
+
 #ifdef __cplusplus
 #if __cplusplus
 }
index 4b7147b..341933e 100644 (file)
@@ -7,6 +7,40 @@
 #include <string>  
 #include <memory>  
 
+#define TOTAL_MUSIC_SPACE (10 * 1024 * 1024) // 10M
+#define TOTAL_MUSIC_SPACE_PATH "/user/musci/usermusci"
+
+#define TOTAL_RECORDING_SPACE (10 * 1024 * 1024) // 10M
+#define TOTAL_RECORDING_SPACE_PATH "/user/musci/recording"
+
+#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_PATH "/user/dial/offlinedial"
+
+#define TOTAL_RES_DIAL_SPACE (7 * 1024 * 1024) // 7M
+#define TOTAL_RES_DIAL_SPACE_PATH "/user/dial/resdial"
+
+#define TOTAL_CUSTOM_DAIL_SPACE (1 * 1024 * 1024) // 1M
+#define TOTAL_CUSTOM_DAIL_SPACE_PATH "/user/dial/customdial"
+
+#define TOTAL_SYSTEM_SPACE (5 * 1024 * 1024) // 5M
+#define TOTAL_SYSTEM_SPACE_PATH "/user/system"
+
+#define TOTAL_RES_SPACE (40 * 1024 * 1024) // 40M
+#define TOTAL_RES_SPACE_PATH "/user/user/res"
+
+#define TOTAL_USERDATA_SPACE (5 * 1024 * 1024) // 5M
+#define TOTAL_USERDATA_SPACE_PATH "/user/user/userdata"
+
+#define TOTAL_UPDATE_SPACE (15 * 1024 * 1024) // 15M
+#define TOTAL_UPDATE_SPACE_PATH "/user/update"
+
+#define TOTAL_SPACE_SIZE (TOTAL_MUSIC_SPACE + TOTAL_RECORDING_SPACE + TOTAL_RING_SPACE + TOTAL_DIAL_SPACE + TOTAL_RES_DIAL_SPACE + TOTAL_CUSTOM_DAIL_SPACE + TOTAL_SYSTEM_SPACE + TOTAL_RES_SPACE + TOTAL_USERDATA_SPACE + TOTAL_UPDATE_SPACE) // 总空间大小
+
+#define TOTAL_SYSTEM_SIZE (128 * 1024 * 1024) // 系统空间大小
+
 namespace OHOS {  
 
 enum class SystemLogType {  
@@ -45,7 +79,13 @@ public:
     size_t getLogSize() const; // 获取日志数量  
     uint32_t GetCurrentTime(); // 获取当前时间  
     /* ---------------------------------- 系统内存 ---------------------------------- */  
-    std::string get_system_mem_info(); // 获取系统内存信息  
+    std::string get_system_mem_info(); // 获取系统内存信息
+    long long getFolderSize(const char* folderPath);
+    bool canSyncFile(std::string path,uint32_t path_max_size,uint32_t download_size); // 获取文件占用空间大小  
+    long long getResRealSize(void)
+    {
+        return getFolderSize(TOTAL_RES_SPACE_PATH);
+    }
     /* ------------------------------- nextday日志记录 ------------------------------ */  
     bool save_nextday_log(uint32_t timestamp); // 保存nextday日志  
     bool load_nextday_log(); // 加载nextday日志  
index e3ef044..f3924d5 100644 (file)
@@ -22,6 +22,9 @@
 #include <sys/time.h>
 #include <thread>
 #include <vector>
+#include <stdio.h>
+#include <dirent.h>
+#include <sys/stat.h>
 
 #define SYSTEM_LOG_FILE_PATH "/system/system_log.txt"
 #define SYSTEM_LOG_FILE_PATH_NEXTDAY "/system/system_log_nextday.txt"
@@ -181,6 +184,53 @@ std::string SystemLogModel::get_system_mem_info() {
                               : 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;
+    }
+
+    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;
+}
+
+// 检查是否可以同步文件
+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) {
   // 检查容量,最多存储7条日志