修改动画出现的内存泄漏
authorhcj <1224667075@qq.com>
Sat, 31 Aug 2024 07:21:10 +0000 (15:21 +0800)
committerhcj <1224667075@qq.com>
Sat, 31 Aug 2024 07:21:10 +0000 (15:21 +0800)
code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp
code/sdk/application/wearable/service/msg_center/src/notify/transmitting.cpp

index a67451a..179f128 100644 (file)
@@ -35,7 +35,7 @@ namespace OHOS
     static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_VIEW_Y = 0;
     static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_VIEW_W = 466;
     static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_VIEW_H = 466;
-    const char **ShutDownPathsArray{nullptr};                                     // 关机图片路径数组
+    const ImageInfo **ShutDownInfoArray{nullptr};                                     // 关机图片路径数组
     ImageAnimatorInfo ShutDownImageInfo[SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES]; // 关机图像的信息
     #define LOW_POWER_BUTTON "LOW_POWER_BUTTON"
     #define CHARGE_GROUP "UIViewGroup_charge"
@@ -309,7 +309,7 @@ namespace OHOS
         group->SetPosition(0, 0, 466, 466);
 
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShutDownAnimatorView::ShowUpShutDownAnimatorView");
-        ShutDownPathsArray = CreateImagePathsArray(ShutDownPaths, SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
+        ShutDownInfoArray = CreateImageInfoArray(ShutDownPaths, SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
 
         if (ShutDownImageAnimatorView == nullptr)
         {
@@ -322,8 +322,8 @@ namespace OHOS
            
             for (uint8_t i = 0; i < SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++)
             {
-                ShutDownImageInfo[i].imagePath = (ShutDownPathsArray[i]);
-                ShutDownImageInfo[i].imageType = IMG_SRC_FILE_PATH;
+                ShutDownImageInfo[i].imageInfo = (ShutDownInfoArray[i]);
+                ShutDownImageInfo[i].imageType = IMG_SRC_IMAGE_INFO;
                 ShutDownImageInfo[i].pos.x = SHUTDOWN_IMAGE_ANIMATOR_VIEW_X;
                 ShutDownImageInfo[i].pos.y = SHUTDOWN_IMAGE_ANIMATOR_VIEW_Y;
                 ShutDownImageInfo[i].width = SHUTDOWN_IMAGE_ANIMATOR_VIEW_W;
@@ -388,11 +388,12 @@ namespace OHOS
             delete ShutDownImageAnimatorView;
             ShutDownImageAnimatorView = nullptr;
             }
+            FreeImageInfoArray(ShutDownInfoArray,ShutDownPaths,SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
             delete group;
             group = nullptr;
 
         }
-        FreeImagePathsArray(ShutDownPathsArray,SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
+        //FreeImagePathsArray(ShutDownPathsArray,SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
       
         RootView::GetInstance()->Remove(UIViewGroup_lowpower);
         delete UIViewGroup_lowpower;
index 0c6d24e..c0b6bde 100644 (file)
@@ -13,6 +13,7 @@
 // #include "UiConfig.h"
 #include "bleEvent.h"
 #include "power_display_service.h"
+#include "uicomponents/UIComponents.h"
 namespace OHOS
 {
     static UIImageView *imageCharge = nullptr;
@@ -28,15 +29,16 @@ namespace OHOS
 
     static UIImageAnimatorView *downImageAnimatorView=nullptr;
 
-    static constexpr char *ShutDownPaths = "/user/res/down/"; //关机图片路径
+    static constexpr char *ShutDownPaths = "/user/res/down/"; 
     static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 24; // 图片帧数
     static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_TIME = 150;           // 图片更新间隔
-    static ImageAnimatorInfo ImageInfo[SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES]; // 关机图像的信息
+    static ImageAnimatorInfo ImageInfo_animator[SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES]; // 关机图像的信息
     static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_VIEW_X = 183;
     static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_VIEW_Y = 140;
     static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_VIEW_W = 100;
     static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_VIEW_H = 100;
-    static const char **PathsArray{nullptr};                                     // 关机图片路径数组
+
+    const ImageInfo **imageInfo_dwon{nullptr};                                     // 关机图片路径数组
 
     #define TRANSMITTING_SUCC_PATH PNG_SUCC_IMAGE;
     #define TRANSMITTING_FAIL_PATH PNG_ATTENTION_IMAGE;
@@ -46,23 +48,12 @@ namespace OHOS
 
     #define LOW_POWER_BUTTON "LOW_POWER_BUTTON"
 
-     static const char ** CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages)
-    {
-        const char **imagePaths = new const char *[numImages];
-        char buffer[256];
-        for (int i = 0; i < numImages; i++)
-        {
-            snprintf(buffer, sizeof(buffer), "%s%d.%s", basePath, i + 1, fileExtension);
-            imagePaths[i] = strdup(buffer);
-            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " imagePaths[%d] = %s", i, imagePaths[i]);
-        }
-        return imagePaths;
-    }
+    
 
     static void  CreatetransmittingAnimator(void)
     {
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShutDownAnimatorView::ShowUpShutDownAnimatorView");
-        PathsArray = CreateImagePathsArray(ShutDownPaths, "bin", SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
+        imageInfo_dwon = CreateImageInfoArray(ShutDownPaths,SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, "bin");
 
         if (downImageAnimatorView == nullptr)
         {
@@ -74,17 +65,17 @@ namespace OHOS
             }
             for (uint8_t i = 0; i < SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++)
             {
-                ImageInfo[i].imagePath = (PathsArray[i]);
-                ImageInfo[i].imageType = IMG_SRC_FILE_PATH;
-                ImageInfo[i].pos.x = SHUTDOWN_IMAGE_ANIMATOR_VIEW_X;
-                ImageInfo[i].pos.y = SHUTDOWN_IMAGE_ANIMATOR_VIEW_Y;
-                ImageInfo[i].width = SHUTDOWN_IMAGE_ANIMATOR_VIEW_W;
-                ImageInfo[i].height = SHUTDOWN_IMAGE_ANIMATOR_VIEW_H;
+                ImageInfo_animator[i].imageInfo = (imageInfo_dwon[i]);
+                ImageInfo_animator[i].imageType = IMG_SRC_IMAGE_INFO;
+                ImageInfo_animator[i].pos.x = SHUTDOWN_IMAGE_ANIMATOR_VIEW_X;
+                ImageInfo_animator[i].pos.y = SHUTDOWN_IMAGE_ANIMATOR_VIEW_Y;
+                ImageInfo_animator[i].width = SHUTDOWN_IMAGE_ANIMATOR_VIEW_W;
+                ImageInfo_animator[i].height = SHUTDOWN_IMAGE_ANIMATOR_VIEW_H;
             }
             downImageAnimatorView->SetPosition(SHUTDOWN_IMAGE_ANIMATOR_VIEW_X, SHUTDOWN_IMAGE_ANIMATOR_VIEW_Y, SHUTDOWN_IMAGE_ANIMATOR_VIEW_W, SHUTDOWN_IMAGE_ANIMATOR_VIEW_H);
             downImageAnimatorView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);
             downImageAnimatorView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
-            downImageAnimatorView->SetImageAnimatorSrc(ImageInfo, SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, 100);
+            downImageAnimatorView->SetImageAnimatorSrc(ImageInfo_animator, SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, 100);
             downImageAnimatorView->SetRepeat(true);
             downImageAnimatorView->SetRepeatTimes(1);
            
@@ -130,6 +121,7 @@ namespace OHOS
         }
         if(downImageAnimatorView)
         {
+            FreeImageInfoArray(imageInfo_dwon,ShutDownPaths, SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES,"bin");
             delete downImageAnimatorView;
             downImageAnimatorView = nullptr;
         }