Merge #2343 into sdk650pathc0423 from refs/changes/2343/head 2345/target/1
author彭磊 <1624952103@qq.com>
Sat, 20 Sep 2025 13:45:33 +0000 (13:45 +0000)
committer彭磊 <1624952103@qq.com>
Sat, 20 Sep 2025 13:45:33 +0000 (13:45 +0000)
优化custom读取文件接口

* refs/changes/2343/head: (1 commits squashed)

  - 优化custom读取文件接口

Signed-off-by: aliyun6865282430 <1624952103@qq.com>
Merged-by: aliyun6865282430 <1624952103@qq.com>
link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/2343
code/sdk/zhihui/utils/custom_utils.c

index d6803c3..55507c3 100644 (file)
@@ -666,7 +666,6 @@ void startup_post_init_task(void)
     uint16_t delay_time = 1500;
     if(factory_test_flag)
     {
-        factory_set_recoder_streamType();
         snprintf(path, 40, "/user/music/FactoryMode.mp3");
         delay_time = 2000;
     }
@@ -677,6 +676,12 @@ void startup_post_init_task(void)
     custom_play_audio(path,100);
     LOS_Msleep(delay_time);
     custom_stop_play_audio();
+
+    if(factory_test_flag)
+    {
+        factory_set_recoder_streamType();
+    }
+
 #endif
 #ifdef SUPPORT_CYWEE_SERVICE
     do_cywee_service_check_msg(CYWEE_SERVICE_CMD_TIME_SYNC,NULL);
@@ -3195,6 +3200,9 @@ void uapi_get_file_data(char *path,uint8_t *data,uint16_t *len)
     FILE *file;
     uint16_t fileSize;
 
+    if(!data)
+        return;
+
     file = fopen(path, "rb"); 
     if (file == NULL) 
     {
@@ -3212,15 +3220,17 @@ void uapi_get_file_data(char *path,uint8_t *data,uint16_t *len)
     }
     else
         fileSize = *len;
-    if(data == NULL)
-        data = (uint8_t *)malloc(fileSize);
-
+    
+    if(fileSize == 0)
+    {
+        fclose(file);
+        return ;
+    }
     size_t bytesRead = fread(data, 1, fileSize, file);
     if (bytesRead != fileSize) 
     {
         PRINT("fread failed \n");
         fclose(file);
-        free(data);
         return ;
     }
     fclose(file);