#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
{
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()
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);
}
//下载成功通知
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");
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);
}
}
}