* @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
*/
#include <stdint.h>
void stopPlayingMusic(void);
void custom_setUpListCase(void);
+ bool canSyncMusic(uint32_t songSize);
#ifdef __cplusplus
#if __cplusplus
#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;
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
}
#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 {
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日志
#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"
: 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条日志