修复ota信号跳变bug
authorxue <2144439972@qq.com>
Fri, 5 Dec 2025 06:44:40 +0000 (14:44 +0800)
committerxue <2144439972@qq.com>
Fri, 5 Dec 2025 06:44:40 +0000 (14:44 +0800)
code/sdk/application/wearable/ln/nativeapp/nativeui/ota/include/OtaModel.h
code/sdk/application/wearable/ln/nativeapp/nativeui/ota/include/OtaView.h
code/sdk/application/wearable/ln/nativeapp/nativeui/ota/src/OtaModel.cpp
code/sdk/application/wearable/ln/nativeapp/nativeui/ota/src/OtaView.cpp

index 5f971e6..cfd660f 100644 (file)
@@ -49,6 +49,8 @@ namespace OHOS
         int GetBatteryLevel();
         bool IsBatteryCharging();
         int GetSignalStrength();
+        int GetCat1PowerStatus() const;
+        void UpdateNetworkStatus();
         int GetOtaPb();
         
         // OTA操作
@@ -97,6 +99,10 @@ namespace OHOS
         bool m_nightUpdateEnabled; // 夜间更新是否启用
 
         std::string m_upgradeDescription; // 升级描述
+        
+        // 网络状态管理
+        int m_cat1PowerStatus;         // CAT1电源状态
+        int m_signalStrength;          // 信号强度
     };
 }
 
index 4c92b29..6f6deb8 100644 (file)
@@ -84,6 +84,7 @@ namespace OHOS
         void UpdateStatusBarDisplay();
         void UpdateBatteryDisplay();
         void UpdateSignalDisplay();
+        void UpdateSignalBarDisplay(int signalBars, bool state);
 
     private:
         void InitUI();
index 42e5ecb..b5ad9b1 100644 (file)
 #include "ota/include/OtaView.h"
 #include "ota/include/OtaUpdatingView.h"
 #include "system/include/MemoryManager.h"
+#ifdef SUPPORT_CAT1_SERVICE
+#include "cat1_pub_api.h"
+#endif
+#ifdef SUPPORT_PPP_SERVICE
+#include "ppp_cat1_api.h"
+#endif
 
 namespace OHOS
 {
@@ -46,6 +52,10 @@ namespace OHOS
             m_nightUpdateEnabled = true;
             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OtaModel: Night update is enabled from KV storage");
         }
+        
+        // 初始化网络状态
+        m_cat1PowerStatus = 0;
+        m_signalStrength = 0;
     }
 
     OtaModel::~OtaModel()
@@ -416,11 +426,42 @@ namespace OHOS
 
     int OtaModel::GetSignalStrength()
     {
-        int sig = 0;
-#if defined(SUPPORT_CAT1_SERVICE) || defined(SUPPORT_PPP_SERVICE)
-        sig = uapi_dev_runtime_get_cat1_signal();
-#endif
-        return sig; 
+        return m_signalStrength;
+    }
+
+    /**
+     * @brief 获取CAT1模块电源状态
+     * @return CAT1电源状态值
+     * @note 0=关机,1=开机,其他值表示电源异常状态
+     */
+    int OtaModel::GetCat1PowerStatus() const
+    {
+        return m_cat1PowerStatus;
+    }
+
+    /**
+     * @brief 更新网络状态
+     * @note 从底层API获取最新的网络状态信息并更新成员变量
+     */
+    void OtaModel::UpdateNetworkStatus()
+    {
+        // 检查屏幕状态:息屏时不更新网络状态,节省功耗
+        int screenState = uapi_get_screen_state();
+        if (screenState != 0) {
+            // 屏幕关闭(screenState != 0 表示息屏),不执行网络状态更新
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UpdateNetworkStatus: Screen is off (state=%d), skip network status update", screenState);
+            return;
+        }
+        
+        // 从底层API获取最新的网络状态信息
+        #if defined(SUPPORT_CAT1_SERVICE) || defined(SUPPORT_PPP_SERVICE)
+        m_cat1PowerStatus = uapi_dev_runtime_get_cat1_powerstat();   // CAT1电源状态
+        m_signalStrength = cat1_api_runtime_get_cat1_signal();       // 信号强度
+        #endif
+        
+        // 记录网络状态更新日志
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"Network status updated: power=%d, signal=%d", 
+                     m_cat1PowerStatus, m_signalStrength);
     }
 
     //下载成功通知
index 3c1b84d..e50f91e 100644 (file)
@@ -28,6 +28,9 @@
 namespace OHOS
 {
     static OtaView *g_pOtaView{nullptr};
+    
+    static const int64_t COLOR_SIGNAL_ON = 0xffffffff;
+    static const int64_t COLOR_SIGNAL_OFF = 0xff909090;
     OtaView::OtaView()
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OtaView::OtaView");
@@ -765,27 +768,54 @@ namespace OHOS
 
     void OtaView::UpdateSignalDisplay()
     {
-        if (NoSignal == nullptr) {
-            return;
+        // 更新网络状态
+        OtaModel::GetInstance()->UpdateNetworkStatus();
+        
+        // 从Model获取网络状态信息  
+        int cat1_powerOn = OtaModel::GetInstance()->GetCat1PowerStatus();  // CAT1电源状态: 1=开机, 0=关机
+        int signal = OtaModel::GetInstance()->GetSignalStrength();  
+        
+        const int SIGNAL_NO_SIGNAL = 0;
+        if (cat1_powerOn == 0)
+        {
+            if (NoSignal != nullptr)
+            {
+                NoSignal->SetVisible(true);
+            }
+            UpdateSignalBarDisplay(signal, false);
         }
-
-        // 获取信号强度(范围通常是0-31)
-        int signalStrength = OtaModel::GetInstance()->GetSignalStrength();
-        bool hasSignal = (signalStrength > 0);
-
-        // 更新无信号图标显示
-        NoSignal->SetVisible(!hasSignal);
-
-        // 更新信号强度指示器
-        for (int i = 0; i < 4; i++) {
-            if (showSignalStrength[i] != nullptr) {
-                // 根据信号强度显示对应的信号条
-                // 信号强度范围0-31,分为4个等级:0-7, 8-15, 16-23, 24-31
-                // 修改逻辑:第1条>=8, 第2条>=16, 第3条>=24, 第4条>=28
-                int threshold = (i + 1) * 8;
-                if (i == 3) threshold = 28; // 第4条在28以上显示
-                bool showBar = (signalStrength >= threshold);
-                showSignalStrength[i]->SetVisible(hasSignal && showBar);
+        else if (cat1_powerOn == 1)
+        {
+            if (signal == SIGNAL_NO_SIGNAL) // 计算信号强度
+            {
+                // 无信号UI显示
+                if (NoSignal != nullptr)
+                {
+                    NoSignal->SetVisible(true);
+                }
+                UpdateSignalBarDisplay(signal, false);
+            }
+            else
+            {
+                if (NoSignal != nullptr)
+                {
+                    NoSignal->SetVisible(false);
+                }
+                UpdateSignalBarDisplay(signal, true);
+            }
+        }
+    }
+    
+    void OtaView::UpdateSignalBarDisplay(int signalBars, bool state)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OtaView::UpdateSignalBarDisplay");
+        for (int i = 0; i < 4; i++)
+        {
+            if (showSignalStrength[i] != nullptr)
+            {
+                showSignalStrength[i]->SetStyle(STYLE_BACKGROUND_COLOR, (i < signalBars) ? COLOR_SIGNAL_ON : COLOR_SIGNAL_OFF);
+                showSignalStrength[i]->Invalidate();
+                showSignalStrength[i]->SetVisible(state);
             }
         }
     }