合并dial文件
authorCaisking <Casiking@zhihuishixun.com>
Wed, 30 Jul 2025 09:39:41 +0000 (17:39 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Wed, 30 Jul 2025 09:39:41 +0000 (17:39 +0800)
15 files changed:
code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialArcLabelView.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialArcProgressView.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialDataBase.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialDigitalImgView.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialLabelView.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialModelSteps.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialModelTime.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialOptionImgView.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialRotateImgView.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialSequenceImgView.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialStaticImgView.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialVideoView.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialViewContainer.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/ModelDialDataFactory.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/WatchInterface.cpp

index 02ce99c..fa4a347 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved.
  */
 
-#include "DialArcLabelView.h"
+#include "main/dial/DialArcLabelView.h"
 #include "securec.h"
 
 namespace OHOS {
index b9ab854..d045de8 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved.
  */
 
-#include "DialArcProgressView.h"
+#include "main/dial/DialArcProgressView.h"
 
 namespace OHOS {
 DialArcProgressView::DialArcProgressView(void)
@@ -13,8 +13,8 @@ DialArcProgressView::~DialArcProgressView(void)
 {
 }
 
-void DialArcProgressView::HandleFloatData(float data) {
-    // printf("HandleFloatData: %f\n", data);
+void DialArcProgressView::HandleFloatData(float data)
+{
     float ratio = data;
     if (ratio > 1.0f) {
         ratio = 1.0f;
@@ -28,4 +28,16 @@ void DialArcProgressView::HandleFloatData(float data) {
     value_ = value;
     SetValue(value_);
 }
+
+void DialArcProgressView::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea)
+{
+    if (foregroundStopCount_ != 0) {
+        Rect rect = GetOrigRect();
+        foregroundGradient_.startX = rect.GetX();
+        foregroundGradient_.startY = rect.GetY();
+        foregroundGradient_.endX = rect.GetRight();
+        foregroundGradient_.endY = rect.GetBottom();
+    }
+    UICircleProgress::OnDraw(gfxDstBuffer, invalidatedArea);
+}
 }
\ No newline at end of file
index 4f31617..50e7b59 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved.
  */
 
-#include "DialDigitalImgView.h"
+#include "main/dial/DialDigitalImgView.h"
 #include <cmath>
 #include "securec.h"
 
index 526d0a2..38a544f 100644 (file)
  * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved.
  */
 
-#include "DialLabelView.h"
+#include "main/dial/DialLabelView.h"
 #include "securec.h"
 
-namespace OHOS
+namespace OHOS {
+DialLabelView::DialLabelView(void)
 {
-    DialLabelView::DialLabelView(void)
-    {
-    }
+}
 
-    DialLabelView::~DialLabelView(void)
-    {
-        if (text_ != nullptr)
-        {
-            UIFree(text_);
-        }
+DialLabelView::~DialLabelView(void)
+{
+    if (text_ != nullptr) {
+        UIFree(text_);
     }
+}
 
-    bool DialLabelView::SetText(const char *text)
-    {
-        if (text == nullptr)
-        {
-            return false;
-        }
-        UILabel::SetText(text);
-        return true;
+bool DialLabelView::SetText(const char* text)
+{
+    if (text == nullptr) {
+        return false;
     }
+    UILabel::SetText(text);
+    return true;
+}
 
-    void DialLabelView::SetTextWithWildcardInner(const char *text)
-    {
-        if (strcmp(text, dstBuf_) == 0)
-        {
-            return;
-        }
-        memset_s(dstBuf_, sizeof(dstBuf_), 0, sizeof(dstBuf_));
-        if (strcpy_s(dstBuf_, MAX_BUF_SIZE, text) != EOK)
-        {
-            GRAPHIC_LOGE("strcpy_s failed!\n");
-        }
-        UILabel::SetText(dstBuf_);
+void DialLabelView::SetTextWithWildcardInner(const char* text)
+{
+    if (strcmp(text, dstBuf_) == 0) {
+        return;
     }
+    memset_s(dstBuf_, sizeof(dstBuf_), 0, sizeof(dstBuf_));
+    if (strcpy_s(dstBuf_, MAX_BUF_SIZE, text) != EOK) {
+        GRAPHIC_LOGE("strcpy_s failed!\n");
+    }
+    UILabel::SetText(dstBuf_);
+}
 
-    bool DialLabelView::SetTextWithWildcard(const char *text)
-    {
-        if (text == nullptr)
-        {
-            return false;
-        }
-        if (text_ != nullptr)
-        {
-            if (strcmp(text, text_) == 0)
-            {
-                return true;
-            }
-            UIFree(text_);
-            text_ = nullptr;
+bool DialLabelView::SetTextWithWildcard(const char* text)
+{
+    if (text == nullptr) {
+        return false;
+    }
+    if (text_ != nullptr) {
+        if (strcmp(text, text_) == 0) {
+            return true;
         }
+        UIFree(text_);
+        text_ = nullptr;
+    }
 
-        uint32_t textLen = static_cast<uint32_t>(strlen(text));
-        if (textLen > (MAX_BUF_SIZE - 1))
-        {
-            return false;
-        }
-        text_ = static_cast<char *>(UIMalloc(++textLen));
-        if (text_ == nullptr)
-        {
-            return false;
-        }
-           if (strcpy_s(text_, textLen, text) != EOK) {
-               GRAPHIC_LOGE("strcpy_s failed");
-               UIFree(text_);
-               text_ = nullptr;
-               return false;
-           }
-        return true;
+    uint32_t textLen = static_cast<uint32_t>(strlen(text));
+    if (textLen > (MAX_BUF_SIZE - 1)) {
+        return false;
+    }
+    text_ = static_cast<char*>(UIMalloc(++textLen));
+    if (text_ == nullptr) {
+        return false;
     }
+    if (strcpy_s(text_, textLen, text) != EOK) {
+        GRAPHIC_LOGE("strcpy_s failed");
+        UIFree(text_);
+        text_ = nullptr;
+        return false;
+    }
+    return true;
+}
 
-    void DialLabelView::HandleTextData(const std::string *data, uint16_t num)
-    {
-        if (num == 0 || data == nullptr)
-        {
-            // GRAPHIC_LOGE("Invalid data or num.");
+void DialLabelView::HandleTextData(const std::string* data, uint16_t num)
+{
+    char tempBuf[MAX_BUF_SIZE] = {0};
+    if (num == 1) {
+        if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0].c_str()) < 0) {
+            GRAPHIC_LOGE("snprintf_s failed.\n");
             return;
         }
-
-        // printf("HandleTextData called with num: %d, data[0]: %s\n", num, data[0].c_str());
-
-        char tempBuf[MAX_BUF_SIZE] = {0};
-
-        int ret;
-        switch (num)
-        {
-        case 1:
-            ret = snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0].c_str());
-            break;
-        case 2:
-            ret = snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0].c_str(), data[1].c_str());
-            break;
-        case 3:
-            ret = snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_,
-                             data[0].c_str(), "年", data[1].c_str(), "月", data[2].c_str(), "日");
-            break;
-        case 4: /*8月7号  星期三*/
-            ret = snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_,
-                             data[0].c_str(), data[1].c_str(), data[2].c_str());
-            break;
-        default:
-            GRAPHIC_LOGE("Invalid num: %d. Max size is 3.\n", num);
+    } else if (num == 2) { // 2: wildcard cnt
+        if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0].c_str(), data[1].c_str()) < 0) {
+            GRAPHIC_LOGE("snprintf_s failed.\n");
             return;
         }
-
-        if (ret < 0)
-        {
-            GRAPHIC_LOGE("snprintf_s failed with error code: %d\n", ret);
+    } else if (num == 3) { // 3: wildcard cnt
+        if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_,
+            data[0].c_str(), data[1].c_str(), data[2].c_str()) < 0) { // 2: index
+            GRAPHIC_LOGE("snprintf_s failed.\n");
             return;
         }
-
-        // printf("Constructed tempBuf: %s\n", tempBuf);
-        SetTextWithWildcardInner(tempBuf);
+    } else {
+        GRAPHIC_LOGE("max size is 3.\n");
+        return;
     }
-    void DialLabelView::HandleFloatData(const float *data, uint16_t num)
-    {
-        char tempBuf[MAX_BUF_SIZE] = {0};
-        if (num == 1)
-        {
-            if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0]) < 0)
-            {
-                GRAPHIC_LOGE("snprintf_s failed.\n");
-                return;
-            }
-        }
-        else if (num == 2)
-        { // 2: wildcard cnt
-            if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0], data[1]) < 0)
-            {
-                GRAPHIC_LOGE("snprintf_s failed.\n");
-                return;
-            }
-        }
-        else if (num == 3)
-        { // 3: wildcard cnt
-            if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0], data[1], data[2]) < 0)
-            { // 2: index
-                GRAPHIC_LOGE("snprintf_s failed.\n");
-                return;
-            }
+    SetTextWithWildcardInner(tempBuf);
+}
+
+void DialLabelView::HandleFloatData(const float* data, uint16_t num)
+{
+    char tempBuf[MAX_BUF_SIZE] = {0};
+    if (num == 1) {
+        if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0]) < 0) {
+            GRAPHIC_LOGE("snprintf_s failed.\n");
+            return;
         }
-        else
-        {
-            GRAPHIC_LOGE("max size is 3.\n");
+    } else if (num == 2) { // 2: wildcard cnt
+        if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0], data[1]) < 0) {
+            GRAPHIC_LOGE("snprintf_s failed.\n");
             return;
         }
-        SetTextWithWildcardInner(tempBuf);
-    }
-
-    void DialLabelView::HandleFloatData(float data)
-    {
-        char tempBuf[MAX_BUF_SIZE] = {0};
-        if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data) < 0)
-        {
+    } else if (num == 3) { // 3: wildcard cnt
+        if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0], data[1], data[2]) < 0) { // 2: index
             GRAPHIC_LOGE("snprintf_s failed.\n");
             return;
         }
-        SetTextWithWildcardInner(tempBuf);
+    } else {
+        GRAPHIC_LOGE("max size is 3.\n");
+        return;
     }
-    void DialLabelView::SetLang(uint8_t lang)
-    {
-        language_ = lang;
-        OnLangChange(FontGlobalManager::GetInstance()->GetCurrentLangId());
+    SetTextWithWildcardInner(tempBuf);
+}
+
+void DialLabelView::HandleFloatData(float data)
+{
+    char tempBuf[MAX_BUF_SIZE] = {0};
+    if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data) < 0) {
+        GRAPHIC_LOGE("snprintf_s failed.\n");
+        return;
     }
+    SetTextWithWildcardInner(tempBuf);
+}
 
-    void DialLabelView::OnLangChange(uint8_t langId)
-    {
-        if (language_ == FontGlobalManager::INVALID_LANG_ID)
-        {
-            SetVisible(true);
-        }
-        else if (language_ == langId)
-        {
-            SetVisible(true);
-        }
-        else
-        {
-            SetVisible(false);
-        }
+void DialLabelView::SetLang(uint8_t lang)
+{
+    language_ = lang;
+    OnLangChange(FontGlobalManager::GetInstance()->GetCurrentLangId());
+}
+
+void DialLabelView::OnLangChange(uint8_t langId)
+{
+    if (language_ == FontGlobalManager::INVALID_LANG_ID) {
+        SetVisible(true);
+    } else if (language_ == langId) {
+        SetVisible(true);
+    } else {
+        SetVisible(false);
     }
+}
 }
\ No newline at end of file
index 3eeb3ff..6050117 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #include "DialModelSteps.h"
-#include "RegisterDialModel.h"
+#include "main/dial/RegisterDialModel.h"
 #include "goal/include/goalmodel.h"
 
 REGIST_DIAL_MODULE(OHOS::DialDataType::STEP_COUNT,
index a08366b..e710dd9 100644 (file)
@@ -7,8 +7,8 @@
 
 #include <cmath>
 #include "sys/time.h"
-#include "RegisterDialModel.h"
-#include "DialModelTime.h"
+#include "main/dial/RegisterDialModel.h"
+#include "main/dial/DialModelTime.h"
 #include "components/root_view.h"
 #include "custom_runtime.h"
 
@@ -42,6 +42,8 @@ REGIST_DIAL_MODULE_YEAR(OHOS::DialDataType::SOLAR_YEAR, OHOS::DialModelTime::Get
 REGIST_DIAL_MODULE_GEAR_POSITIVE(OHOS::DialDataType::SWIVEL_GEAR_POSITIVE, OHOS::DialModelTime::GetInstance());
 REGIST_DIAL_MODULE_GEAR_NEGATIVE(OHOS::DialDataType::SWIVEL_GEAR_NEGATIVE, OHOS::DialModelTime::GetInstance());
 
+static OHOS::RegisterDialModel REGIST_MOUNTH_80(OHOS::DialDataType::MONTH_DATA, OHOS::DialModelTime::GetInstance());
+
 namespace OHOS {
 static constexpr int16_t S_MS_US_TRANS = 1000;      // 1000: seconds, milliseconds, microsecond transform value
 static constexpr uint8_t ONE_MINUTE_IN_SECOND = 60; // 60: 60 seconds per minute
@@ -148,37 +150,37 @@ bool DialModelTime::GetDialFloatData(DialDataType& type, float& out)
     }
 
     switch (type) {
-        case OHOS::DialDataType::CLOCK_ANGLE:
+        case DialDataType::CLOCK_ANGLE:
             out = static_cast<float>(angleH_);
             break;
-        case OHOS::DialDataType::MINUTE_ANGLE:
+        case DialDataType::MINUTE_ANGLE:
             out = static_cast<float>(angleM_);
             break;
-        case OHOS::DialDataType::SECOND_ANGLE:
+        case DialDataType::SECOND_ANGLE:
             out = static_cast<float>(angleS_);
             break;
-        case OHOS::DialDataType::MILLISECOND_ANGLE:
+        case DialDataType::MILLISECOND_ANGLE:
             out = static_cast<float>(angleMS_);
             break;
-        case OHOS::DialDataType::SOLAR_YEAR:
-            out = static_cast<float>(tblock_->tm_year + 1900);
+        case DialDataType::SOLAR_YEAR:
+            out = static_cast<float>(tblock_->tm_year + 1900); // 1900: since 1900
             break;
-        case OHOS::DialDataType::MONTH:
-            out = static_cast<float>(tblock_->tm_mon + 1);
+        case DialDataType::MONTH:
+            out = static_cast<float>(tblock_->tm_mon);
             break;
-        case OHOS::DialDataType::WEEKDAY_DATA:
+        case DialDataType::WEEKDAY_DATA:
             out = static_cast<float>(tblock_->tm_wday);
             break;
-        case OHOS::DialDataType::DATE:
+        case DialDataType::DATE:
             out = static_cast<float>(tblock_->tm_mday);
             break;
-        case OHOS::DialDataType::CLOCK:
+        case DialDataType::CLOCK:
             out = static_cast<float>(tblock_->tm_hour);
             break;
-        case OHOS::DialDataType::MINUTE_TIME:
+        case DialDataType::MINUTE_TIME:
             out = static_cast<float>(tblock_->tm_min);
             break;
-        case OHOS::DialDataType::SECOND_TIME:
+        case DialDataType::SECOND_TIME:
             out = static_cast<float>(tblock_->tm_sec);
             break;
         case DialDataType::SWIVEL_GEAR_POSITIVE: {
@@ -193,6 +195,10 @@ bool DialModelTime::GetDialFloatData(DialDataType& type, float& out)
             out = static_cast<float>(accleratedAngle * -1.0 + CIRCLE_IN_DEGREE);
             break;
         }
+        case DialDataType::MONTH_DATA: {
+            out = static_cast<float>(tblock_->tm_mon) + 1.0;
+            break;
+        }
         default:
             return false;
     }
index 980d438..4175937 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved.
  */
 
-#include "DialOptionImgView.h"
+#include "main/dial/DialOptionImgView.h"
 #include "securec.h"
 
 namespace OHOS {
index bec17ca..171aeea 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved.
  */
 
-#include "DialRotateImgView.h"
+#include "main/dial/DialRotateImgView.h"
 
 namespace OHOS {
 DialRotateImgView::DialRotateImgView(void)
index c7d1c24..8741d4c 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved.
  */
 
-#include "DialSequenceImgView.h"
+#include "main/dial/DialSequenceImgView.h"
 #include "securec.h"
 #include "common/graphic_utils.h"
 #include "common/image_cache_manager.h"
index ffc87a7..bfa5182 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved.
  */
 
-#include "DialStaticImgView.h"
+#include "main/dial/DialStaticImgView.h"
 
 namespace OHOS {
 DialStaticImgView::DialStaticImgView()
index 13113cd..9ac7b75 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved.
  */
 
-#include "DialVideoView.h"
+#include "main/dial/DialVideoView.h"
 
 namespace OHOS {
 static constexpr int16_t JPEG_HEIGHT_DIVISOR = 2;
@@ -23,8 +23,7 @@ DialVideoView::DialVideoView()
 DialVideoView::~DialVideoView()
 {
     if (videoPlayer_ != nullptr) {
-      delete videoPlayer_;
-      videoPlayer_ = nullptr;
+        delete videoPlayer_;
     }
 }
 
index 8ed4cf7..198c067 100644 (file)
@@ -5,9 +5,9 @@
  * Create: 2025-02-06
  */
 
-#include "DialViewContainer.h"
-#include "DialDigitalImgView.h"
-#include "ModelDialDataFactory.h"
+#include "main/dial/DialViewContainer.h"
+#include "main/dial/DialDigitalImgView.h"
+#include "main/dial/ModelDialDataFactory.h"
 
 namespace OHOS {
 DialViewContainer::~DialViewContainer()
index d17de5b..71ea7a1 100644 (file)
@@ -5,7 +5,7 @@
  * Create: 2023-12
  */
 
-#include "ModelDialDataFactory.h"
+#include "main/dial/ModelDialDataFactory.h"
 namespace OHOS {
 bool ModelDialDataFactory::GetDialTextData(DialDataType& type, std::string*& out, int16_t& strNum)
 {
index 45e6359..11f9844 100644 (file)
@@ -6,24 +6,35 @@
  */
 
 #include <string>
+#include <unistd.h>
 #include "dirent.h"
-#include "DialBinParser.h"
+#include "main/DialBinParser.h"
 #include "UiConfig.h"
-#include "WatchInterface.h"
+#include "main/dial/WatchInterface.h"
 #include "gfx_utils/vector.h"
 #include "common/screen.h"
-#include "MainModel.h"
-#include "MainViewSample.h"
-#include "SetDialModel.h"
+#include "main/MainModel.h"
+#include "main/MainViewSample.h"
+#include "set_dial/SetDialModel.h"
 #include "graphic_service.h"
 #include "NativeAbility.h"
+#include "graphic_mutex.h"
+#include "set_dial/SetDialModel.h"
+#include "set_dial/SetDialPresenter.h"
+#include "power_display_service.h"
 
 using namespace OHOS;
 namespace {
-struct {
-    Graphic::Vector<std::string> fileNames;      // only for 3.0
-    Graphic::Vector<watch_dial_info> watchInfo;  // only for 3.0
-} g_info;
+struct WatchInfoInner {
+    std::string fileName;
+    watch_dial_info watchInfo;
+};
+
+Graphic::Vector<WatchInfoInner> g_info;
+GraphicMutex g_mutex;
+GraphicCond g_cond;
+bool g_eventFinished = true;
+const uint16_t INVALID_INFO_INDEX = 0xFFFF;
 
 bool GetActiveWatchPath(std::string &path)
 {
@@ -34,7 +45,7 @@ bool GetActiveWatchPath(std::string &path)
     return false;
 }
 
-bool GetPreviewInfo(const std::string &fileName, DialPreviewInfo &preview)
+bool GetPreviewInfo(const std::string &fileName, DialPreviewInfo &preview, bool isNeedVerify = false)
 {
     const std::string type(".bin");
     if (!(fileName.length() > type.length() &&
@@ -45,7 +56,7 @@ bool GetPreviewInfo(const std::string &fileName, DialPreviewInfo &preview)
     FILE *file = fopen(fileName.c_str(), "rb");
     bool isSuccess = false;
     if (file != nullptr) {
-        isSuccess = DialBinParserManager::GetInstance()->GetDialPreviewInfo(file, &preview);
+        isSuccess = DialBinParserManager::GetInstance()->GetDialPreviewInfo(fileName, file, &preview, isNeedVerify);
         fclose(file);
     }
     return isSuccess;
@@ -70,19 +81,14 @@ bool ConvertPreview2WatchDialInfo(const DialPreviewInfo &preview, watch_dial_inf
     return true;
 }
 
-#define APP_DIAL_PATH  "user/dial/"  //为了编译过加的
-
-bool GetAllWatchInfo()
+void RefreshAllWatchInfo()
 {
-    g_info.fileNames.Clear();
-    g_info.watchInfo.Clear();
+    g_info.Clear();
     struct dirent *direntp = nullptr;
 
-    
-    // ��Ŀ¼
+    // 打开目录
     DIR *dirp = opendir(APP_DIAL_PATH);
-    bool isSuccess = true;
-    // �����ļ�
+    // 遍历文件
     DialPreviewInfo info;
     watch_dial_info watchInfo;
     std::string activePath;
@@ -90,56 +96,133 @@ bool GetAllWatchInfo()
     if (dirp != nullptr) {
         while ((direntp = readdir(dirp)) != nullptr) {
             std::string fileName = std::string(APP_DIAL_PATH) + std::string("/") + std::string(direntp->d_name);
-            isSuccess = GetPreviewInfo(fileName, info);
-            if (!isSuccess) {
+            if (!GetPreviewInfo(fileName, info)) {
                 continue;
             }
 
             const std::string lowestVersion("3.0");
             std::string curVersion(info.protocolVersion);
             if (curVersion >= lowestVersion) {
-                isSuccess = ConvertPreview2WatchDialInfo(info, watchInfo);
-                if (!isSuccess) {
+                if (!ConvertPreview2WatchDialInfo(info, watchInfo)) {
                     break;
                 }
                 watchInfo.install_state = true;
                 watchInfo.is_current_watch = isActiveExist ? (activePath == fileName) : false;
-                g_info.fileNames.PushBack(fileName);
-                g_info.watchInfo.PushBack(watchInfo);
+                g_info.PushBack({fileName, watchInfo});
             }
         }
     }
-    // �ر�Ŀ¼
+    // 关闭目录
     closedir(dirp);
-    return isSuccess;
 }
-}  // namespace
 
-bool GetAllWatchFaceInfo(watch_dial_info *info, uint8_t *num, uint8_t maxCnt)
+inline bool IsFileExists(const std::string &file)
+{
+    return access(file.c_str(), F_OK) == 0;
+}
+
+uint16_t FindMaxVersionIndex(uint16_t indexArray[], uint16_t num)
+{
+    if (num == 0) {
+        return INVALID_INFO_INDEX;
+    }
+
+    if (num == 0) {
+        return indexArray[0];
+    }
+    std::string version = reinterpret_cast<char *>(g_info[indexArray[0]].watchInfo.watch_version);
+    uint16_t index = 0;
+    for (uint16_t i = 1; i < num; ++i) {
+        std::string curVerion = std::string(reinterpret_cast<char *>(g_info[indexArray[i]].watchInfo.watch_version));
+        if (curVerion > version) {
+            version = curVerion;
+            index = i;
+        }
+    }
+    if (num > 1) {
+        GRAPHIC_LOGE("There are watches with the same uuid. %u", g_info[indexArray[index]].watchInfo.uuid);
+    }
+    index = indexArray[index];
+    return index;
+}
+
+void GetWatchInfo(uint32_t uuid, uint16_t &index)
+{
+    index = INVALID_INFO_INDEX;
+    if (g_info.IsEmpty()) {
+        RefreshAllWatchInfo();
+    }
+    const uint16_t MAX_INFO_NUM = 128;
+    static uint16_t indexArray[MAX_INFO_NUM];
+    uint16_t num = 0;
+    std::string activePath;
+    bool isActive = GetActiveWatchPath(activePath);
+    bool isNeedRequery = false;
+    for (uint16_t i = 0; i < g_info.Size(); ++i) {
+        if (uuid == g_info[i].watchInfo.uuid && num < MAX_INFO_NUM) {
+            if (IsFileExists(g_info[i].fileName)) {
+                g_info[i].watchInfo.is_current_watch = isActive ? (g_info[i].fileName == activePath) : false;
+                indexArray[num++] = i;
+            } else {
+                RefreshAllWatchInfo();
+                isNeedRequery = true;
+                break;
+            }
+        }
+    }
+
+    if (!isNeedRequery) {
+        index = FindMaxVersionIndex(indexArray, num);
+        return;
+    }
+    num = 0;
+    for (uint16_t i = 0; i < g_info.Size(); ++i) {
+        if (uuid == g_info[i].watchInfo.uuid && num < MAX_INFO_NUM) {
+            indexArray[num++] = i;
+        }
+    }
+    index = FindMaxVersionIndex(indexArray, num);
+}
+
+void TryToTurnOnScreen()
+{
+    const power_display_svr_api_t *ctx = power_display_svr_get_api();
+    if (ctx == nullptr) {
+        return;
+    }
+    if (ctx->get_screen_state != nullptr && ctx->get_screen_state() != SCREEN_ON) {
+        if (ctx->turn_on_screen != nullptr) {
+            ctx->turn_on_screen();
+        }
+    }
+}
+}  // anonymous namespace
+
+bool GetAllWatchFaceInfo(watch_dial_info **info, uint8_t *num)
 {
     if (info == nullptr || num == nullptr) {
         GRAPHIC_LOGE("para error!");
         return false;
     }
-    if (!GetAllWatchInfo()) {
-        GRAPHIC_LOGE("failed to get all watch info.");
-        return false;
+    GraphicLockGuard guard(g_mutex);
+    while (!g_eventFinished) {
+        g_cond.Wait(g_mutex);
     }
-    if (g_info.watchInfo.Size() > maxCnt) {
-        GRAPHIC_LOGE("mem is not enough.");
-        return false;
-    }
-    *num = g_info.watchInfo.Size();
+    RefreshAllWatchInfo();
+    *num = g_info.Size();
     if (*num == 0) {
-        return false;
+        *info = nullptr;
+        return true;
     }
-    if (memcpy_s(info,
-            g_info.watchInfo.Size() * sizeof(watch_dial_info),
-            &g_info.watchInfo[0],
-            g_info.watchInfo.Size() * sizeof(watch_dial_info)) != 0) {
-        GRAPHIC_LOGE("copy info error!");
+    watch_dial_info *mem = static_cast<watch_dial_info *>(malloc(*num * sizeof(watch_dial_info)));
+    if (mem == nullptr) {
+        GRAPHIC_LOGE("failed to malloc");
         return false;
     }
+    for (uint16_t i = 0; i < g_info.Size(); ++i) {
+        memcpy_s(&mem[i], sizeof(watch_dial_info), &g_info[i].watchInfo, sizeof(watch_dial_info));
+    }
+    *info = mem;
     return true;
 }
 
@@ -149,17 +232,19 @@ bool GetWatchFaceInfo(uint32_t uuid, watch_dial_info *watch)
         GRAPHIC_LOGE("para error!");
         return false;
     }
-    if (!GetAllWatchInfo()) {
-        GRAPHIC_LOGE("failed to get all watch info.");
+
+    uint16_t index = INVALID_INFO_INDEX;
+    GraphicLockGuard guard(g_mutex);
+    while (!g_eventFinished) {
+        g_cond.Wait(g_mutex);
+    }
+    GetWatchInfo(uuid, index);
+    if (index == INVALID_INFO_INDEX) {
+        GRAPHIC_LOGE("uuid %u does not exist", uuid);
         return false;
     }
-    for (uint16_t i = 0; i < g_info.watchInfo.Size(); ++i) {
-        if (g_info.watchInfo[i].uuid == uuid) {
-            *watch = g_info.watchInfo[i];
-            return true;
-        }
-    }
-    return false;
+    memcpy_s(watch, sizeof(watch_dial_info), &g_info[index].watchInfo, sizeof(watch_dial_info));
+    return true;
 }
 
 bool GetWatchCapability(watch_dev_cap_info *capability)
@@ -238,98 +323,118 @@ bool GetCurrentWatchFaceInfo(watch_dial_info *watch)
 
 bool SetCurrentWatchFace(uint32_t uuid)
 {
-    if (!GetAllWatchInfo()) {
-        GRAPHIC_LOGE("failed to get all watch info.");
+    uint16_t index = INVALID_INFO_INDEX;
+    GraphicLockGuard guard(g_mutex);
+    while (!g_eventFinished) {
+        g_cond.Wait(g_mutex);
+    }
+    GetWatchInfo(uuid, index);
+    if (index == INVALID_INFO_INDEX) {
+        GRAPHIC_LOGE("uuid %u does not exist", uuid);
         return false;
     }
-    watch_dial_info info;
-    uint16_t index = 0;
-    bool isExists = false;
-    for (uint16_t i = 0; i < g_info.watchInfo.Size(); ++i) {
-        if (uuid == g_info.watchInfo[i].uuid) {
-            isExists = true;
-            info = g_info.watchInfo[i];
-            index = i;
-            break;
-        }
-    }
-    if (!isExists) {
-        GRAPHIC_LOGE("uuid does not exist!");
-        return false;
+    DialSetting setting = MainModel::GetInstance().GetDialSetting();
+    setting.dialFlag = 1;
+    setting.dialFullName = g_info[index].fileName;
+    if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_SET_DIAL) {
+        GraphicService::GetInstance()->PostGraphicEvent([setting]() {
+            if (SetDialPresenter::GetCurrentInstance() != nullptr) {
+                SetDialPresenter::GetCurrentInstance()->SpecifyDialSetting(setting);
+            }
+        });
+        NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE);
+        return true;
     }
-    if (info.is_current_watch) {
+    if (g_info[index].watchInfo.is_current_watch) {
         return true;
     }
-
-    DialSetting setting = MainModel::GetInstance().GetDialSetting();
-    setting.dialFlag = 1;
-    setting.dialFullName = g_info.fileNames[index];
+    g_eventFinished = false;
     GraphicService::GetInstance()->PostGraphicEvent([setting]() {
+        GraphicLockGuard guardGraphic(g_mutex);
         MainModel::GetInstance().GetDialSetting() = setting;
-        #ifdef fd230_650 
         MainModel::GetInstance().AddDialSetting(setting);
-        #endif
-        if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAIN) {
-            #ifdef fd230_650 
+        if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAIN_SAMPLE) {
             MainViewSample::GetInstance()->ReloadWatchFace();
-            #endif
         }
+        g_eventFinished = true;
+        g_cond.Signal();
     });
+    TryToTurnOnScreen();
 
     return true;
 }
 
 bool UninstallWatch(uint32_t uuid)
 {
-    if (!GetAllWatchInfo()) {
-        GRAPHIC_LOGE("failed to get all watch info.");
-        return false;
-    }
-    watch_dial_info info;
-    uint16_t index = 0;
-    bool isExists = false;
-    for (uint16_t i = 0; i < g_info.watchInfo.Size(); ++i) {
-        if (uuid == g_info.watchInfo[i].uuid) {
-            isExists = true;
-            info = g_info.watchInfo[i];
-            index = i;
-            break;
-        }
-    }
-    if (!isExists) {
-        GRAPHIC_LOGE("uuid does not exist!");
+    uint16_t index = INVALID_INFO_INDEX;
+    GraphicLockGuard guard(g_mutex);
+    while (!g_eventFinished) {
+        g_cond.Wait(g_mutex);
+    }
+    GetWatchInfo(uuid, index);
+    if (index == INVALID_INFO_INDEX) {
+        GRAPHIC_LOGE("uuid %u does not exist", uuid);
         return false;
     }
 
-    if (info.is_current_watch) {
-        DialSetting setting = MainModel::GetInstance().GetDialSetting();
+    DialSetting setting = MainModel::GetInstance().GetDialSetting();
+    if (g_info[index].watchInfo.is_current_watch) {
         setting.dialFlag = 0;
         setting.dialId = 0;
-        std::string fileName = g_info.fileNames[index];
-        GraphicService::GetInstance()->PostGraphicEvent([setting, fileName]() {
-            MainModel::GetInstance().GetDialSetting() = setting;
-            #ifdef fd230_650 
-            MainModel::GetInstance().AddDialSetting(setting,0);
-            #endif
-            if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAIN) {
-                #ifdef fd230_650 
-                MainViewSample::GetInstance()->ReloadWatchFace();
-                #endif
-            }
-            if (remove(fileName.c_str()) != 0) {
-                GRAPHIC_LOGE("failed to remove file %s", fileName.c_str());
+    }
+    if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_SET_DIAL) {
+        if (g_info[index].watchInfo.is_current_watch) {
+            // If it is the current watch face, set it as the default watch face. Otherwise, the configuration remains
+            // unchanged.
+            GraphicService::GetInstance()->PostGraphicEvent([setting]() {
+                if (SetDialPresenter::GetCurrentInstance() != nullptr) {
+                    SetDialPresenter::GetCurrentInstance()->SpecifyDialSetting(setting);
+                }
+            });
+        }
+        NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE);
+        g_eventFinished = false;
+        GraphicService::GetInstance()->PostGraphicEvent([index]() {
+            GraphicLockGuard guardGraphic(g_mutex);
+            ImageCacheManager::GetInstance().UnloadAllInMultiRes(g_info[index].fileName);
+            if (remove(g_info[index].fileName.c_str()) != 0) {
+                GRAPHIC_LOGE("failed to remove file %s", g_info[index].fileName.c_str());
+                g_eventFinished = true;
+                g_cond.Signal();
+                return;
             }
+            g_info.Erase(index);
+            g_eventFinished = true;
+            g_cond.Signal();
         });
-    } else {
-        if (remove(g_info.fileNames[index].c_str()) != 0) {
-            GRAPHIC_LOGE("failed to remove file %s", g_info.fileNames[index].c_str());
-            return false;
-        }
+        return true;
     }
+
+    g_eventFinished = false;
+    GraphicService::GetInstance()->PostGraphicEvent([index, setting]() {
+        GraphicLockGuard guardGraphic(g_mutex);
+        if (g_info[index].watchInfo.is_current_watch &&
+            NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAIN_SAMPLE) {
+            MainModel::GetInstance().GetDialSetting() = setting;
+            MainModel::GetInstance().AddDialSetting(setting);
+            MainViewSample::GetInstance()->ReloadWatchFace();
+        }
+        ImageCacheManager::GetInstance().UnloadAllInMultiRes(g_info[index].fileName);
+        if (remove(g_info[index].fileName.c_str()) != 0) {
+            GRAPHIC_LOGE("failed to remove file %s", g_info[index].fileName.c_str());
+            g_eventFinished = true;
+            g_cond.Signal();
+            return;
+        }
+        g_info.Erase(index);
+        g_eventFinished = true;
+        g_cond.Signal();
+    });
+    TryToTurnOnScreen();
     return true;
 }
 
-bool InstallWatch(const char *path, uint32_t *uuid)
+bool GetUuidByPath(const char *path, uint32_t *uuid)
 {
     if (path == nullptr || uuid == nullptr) {
         GRAPHIC_LOGE("para error!");
@@ -337,49 +442,31 @@ bool InstallWatch(const char *path, uint32_t *uuid)
     }
 
     DialPreviewInfo preview;
-    if (!GetPreviewInfo(std::string(path), preview)) {
+    if (!GetPreviewInfo(std::string(path), preview, true)) {
         return false;
     }
     if (std::string(preview.protocolVersion) < std::string("3.0")) {
         return false;
     }
-    *uuid = preview.uuid;
 
-    if (!GetAllWatchInfo()) {
-        GRAPHIC_LOGE("failed to get all watchinfo!");
-        return false;
-    }
-    for (uint16_t i = 0; i < g_info.watchInfo.Size(); ++i) {
-        const std::string &fileName = g_info.fileNames[i];
-        const watch_dial_info &info = g_info.watchInfo[i];
-        if (!(info.uuid == *uuid && std::string(path) != fileName)) {
-            continue;
-        }
-
-        if (info.is_current_watch) {
-            DialSetting setting = MainModel::GetInstance().GetDialSetting();
-            setting.dialFlag = 1;
-            setting.dialFullName = std::string(path);
-            GraphicService::GetInstance()->PostGraphicEvent([setting, fileName]() {
-                MainModel::GetInstance().GetDialSetting() = setting;
-                #ifdef fd230_650 
-                MainModel::GetInstance().AddDialSetting(setting);
-                #endif
-                if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAIN) {
-                    #ifdef fd230_650 
-                    MainViewSample::GetInstance()->ReloadWatchFace();
-                    #endif
-                }
-                if (remove(fileName.c_str()) != 0) {
-                    GRAPHIC_LOGE("failed to remove file %s", fileName.c_str());
-                }
-            });
-        } else {
-            if (remove(fileName.c_str()) != 0) {
-                return false;
+    watch_dial_info watchInfo;
+    if (ConvertPreview2WatchDialInfo(preview, watchInfo)) {
+        std::string activePath;
+        std::string appendPath(path);
+        bool isActiveExist = GetActiveWatchPath(activePath);
+        watchInfo.install_state = true;
+        watchInfo.is_current_watch = isActiveExist ? (activePath == appendPath) : false;
+        bool isExist = false;
+        for (uint16_t i = 0; i < g_info.Size(); ++i) {
+            if (g_info[i].fileName == appendPath) {
+                isExist = true;
+                break;
             }
         }
+        if (!isExist) {
+            g_info.PushBack({appendPath, watchInfo});
+        }
     }
-
+    *uuid = preview.uuid;
     return true;
 }
\ No newline at end of file