优化PPP测试界面 2397/1 2397/head 2398/target/1
authorpenglei <1624952103@qq.com>
Thu, 25 Sep 2025 08:57:22 +0000 (16:57 +0800)
committerpenglei <1624952103@qq.com>
Thu, 25 Sep 2025 08:57:22 +0000 (16:57 +0800)
code/sdk/zhihui/UI/producttest/src/testView.cpp
code/sdk/zhihui/leiniao/factory_test/PPPTestView.cpp
code/sdk/zhihui/utils/custom_utils.c

index 6fa076e..b874d3c 100644 (file)
@@ -40,7 +40,7 @@ namespace OHOS
     // 2.ViewMapper[] 是一个静态的视图映射数组,将视图ID与MainStopWatchView类中的特定成员函数指针进行了绑定。
     test_ext Test_ViewMapper_t[] = {
         {TESTVIEW, "", "", "", &testView::ChangeSystemAboutView, false}, // 占位,空的
-        {QRCODE, "QRCodeButton", "QRCode", "QRCodeButton_next", &testView::ChangeQRCodeTESTView, true},
+        // {QRCODE, "QRCodeButton", "QRCode", "QRCodeButton_next", &testView::ChangeQRCodeTESTView, true},
         {VISON, "AboutTheWatchButton", "Verison", "AboutTheWatchButton_next", &testView::ChangeSystemAboutView, true},
         {LCD, "LCDButton", "LCD", "LCDButton_next", &testView::ChangeLCDTESTView, true},
         {TP, "TPButton", "TP", "TPButton_next", &testView::ChangeTPTESTView, true},
@@ -52,7 +52,7 @@ namespace OHOS
 #ifdef SUPPORT_CAT1_SERVICE
         {CAT1, "cat1button", "CAT1", "cat1button_next", &testView::ChangeCAT1TESTView, true},
 #endif
-        {BUTTON, "buttonbutton", "oktestBtn", "buttonbutton_next", &testView::ChangKEYTESTView, true},
+        {BUTTON, "buttonbutton", "Button", "buttonbutton_next", &testView::ChangKEYTESTView, true},
         {MICROPHONE, "microphonebutton", "microphone", "microphonebutton_next", &testView::ChangeMPTESTView, true},
         {HRSENSON, "hrsensonbutton", "hrsensor", "hrsensonbutton_next", &testView::ChangeHRTESTView, true},
         {GSENSON, "gsensonbutton", "gsensor", "gsensonbutton_next", &testView::ChangeGTESTView, true},
index 8b39ccc..a1396ef 100644 (file)
@@ -1,5 +1,3 @@
-#include "PPPTestView.h"
-#include "PPPTestModel.h"
 #include "components/ui_scroll_view.h"
 #include "components/root_view.h"
 #include "components/ui_label.h"
 #include "UiConfig.h"
 #include "gfx_utils/style.h"
 #include "graphic_config.h"
-#include "ui_resource_image.h"
+#include "cmsis_os2.h"
+
+// C标准库
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
+
+// 预声明必要的类型以避免循环依赖
+typedef int ppp_error_t;
+
+// PPP错误码常量
+#define PPP_ERR_OK                0
+#define PPP_ERR_TIMEOUT           1
+#define PPP_ERR_AT_FAILED         2
+#define PPP_ERR_DIAL_FAILED       3
+#define PPP_ERR_NO_CARRIER        4
+#define PPP_ERR_BUSY              5
+#define PPP_ERR_NO_DIALTONE       6
+#define PPP_ERR_INVALID_PARAM     7
+#define PPP_ERR_MEMORY            8
+#define PPP_ERR_UART              9
+#define PPP_ERR_INVALID_STATE     10
+#define PPP_ERR_UNKNOWN           11
 
-namespace OHOS
-{
-    static const uint32_t BACK_GROUND_COLOR = 0xff000000; // 黑色背景
-    static const uint32_t TEXT_COLOR = 0xffffffff;        // 白色文字
-    static const uint32_t TITLE_COLOR = 0xff00ff00;       // 绿色标题
-    static PPPTestView *g_pPPPTestView = nullptr;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// 仅包含必要的头文件
+#include "errcode.h"
+#include "service/graphic_service_wrapper.h"
+
+// 确保有这些常量定义(如果errcode.h没有定义的话)
+#ifndef ERRCODE_SUCC
+#define ERRCODE_SUCC  0
+#endif
+#ifndef ERRCODE_FAIL  
+#define ERRCODE_FAIL  1
+#endif
+
+// 前向声明结构体
+struct ppp_network_signal_info_s;
+typedef struct ppp_network_signal_info_s ppp_network_signal_info_t;
+
+// 声明需要使用的函数
+int ppp_env_init(void);
+errcode_t ppp_api_update_all_runtime_status(void);
+ppp_error_t ppp_at_get_network_signal_info(ppp_network_signal_info_t *info);
+errcode_t ppp_get_network_signal_info(void);
+
+// CAT1 API 声明
+uint8_t cat1_api_runtime_get_cat1_powerstat(void);
+uint8_t cat1_api_runtime_get_cat1_networkstat(void);
+int cat1_api_runtime_get_cat1_signal(void);
+int cat1_api_runtime_get_cat1_simstat(void);
+uint8_t cat1_api_runtime_get_cat1_networktype(void);
+char* cat1_api_runtime_get_cat1_operator(void);
+char* cat1_api_runtime_get_cat1_imei(void);
+char* cat1_api_runtime_get_cat1_iccid(void);
+char* cat1_api_runtime_get_cat1_modemver(void);
+
+// 屏幕控制 API 声明
+void uapi_set_screen_on_api(void);
+void ScreenAlwaysOnCtr(int enable);
 
-    // 标签配置结构体
-    struct PPPLabelConfig_t {
+#ifdef __cplusplus
+}
+#endif
+
+// 定义信号信息结构体(避免包含完整头文件)
+struct ppp_network_signal_info_s {
+    int16_t rxlev;
+    int16_t ber;
+    int16_t rscp;
+    int16_t ecno;
+    int16_t rsrq;
+    int16_t rsrp;
+    bool valid;
+};
+
+// 全局变量
+static OHOS::UIScrollView* g_ppp_test_view = nullptr;
+static OHOS::UIView* g_ppp_saved_view = nullptr;
+static OHOS::UILabel* g_ppp_status_labels[12] = {nullptr}; // 增加到12个标签:标题+11个状态(VER占两行)
+static OHOS::UILabel* g_ppp_title_label = nullptr;
+
+// PPP初始化状态
+static bool g_ppp_init_completed = false;
+static bool g_ppp_init_in_progress = false;
+static int g_ppp_init_retry_count = 0;
+static const int MAX_PPP_INIT_RETRIES = 5;
+
+// 定时器相关
+static osTimerId_t g_ppp_init_timer = NULL;
+static osTimerId_t g_ppp_refresh_timer = NULL;
+static const uint32_t PPP_INIT_TIMEOUT_MS = 5000; // 5秒超时
+static const uint32_t PPP_REFRESH_INTERVAL_MS = 5000; // 5秒刷新间隔(减少定时器冲突)
+
+// 标签配置结构体 - 参考testCAT1的设计
+typedef struct {
     int left;
     int top;
     int width;
     int height;
-        uint32_t textColor;
-        uint8_t fontSize;
+    uint16_t fontSize;
+    uint16_t lineHeight;
     const char* text;
-    };
+    OHOS::UILabel::LineBreakMode lineBreakMode;
+} PPPLabelConfig_t;
 
-    PPPTestView::PPPTestView() 
-    {
-        g_pPPPTestView = this;
-        testView_ = nullptr;
-        savedCurrentView_ = nullptr;
-        titleLabel_ = nullptr;
-        viewInitStatus_ = false;
-        isTestActive_ = false;
-        currentStatus_ = PPPTestStatus::Idle;
-        
-        // 初始化状态标签数组
-        for (int i = 0; i < MAX_STATUS_LABELS; i++) {
-            statusLabels_[i] = nullptr;
-        }
-    }
-
-    PPPTestView::~PPPTestView()
-    {
-        DeInit();
-        g_pPPPTestView = nullptr;
-    }
-
-    PPPTestView *PPPTestView::GetInstance() 
-    { 
-        return g_pPPPTestView; 
+// 创建标签的辅助函数 - 优化为圆形LCD布局
+static OHOS::UILabel* create_ppp_label(const PPPLabelConfig_t& config) {
+    OHOS::UILabel* label = new OHOS::UILabel();
+    if (label == nullptr) {
+        return nullptr;
     }
+    
+    label->SetPosition(config.left, config.top, config.width, config.height);
+    label->SetText(config.text);
+    label->SetFont(OHOS::DEFAULT_VECTOR_FONT_FILENAME, config.fontSize);
+    label->SetStyle(OHOS::STYLE_TEXT_COLOR, OHOS::Color::White().full);
+    label->SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0);
+    label->SetStyle(OHOS::STYLE_TEXT_FONT, config.fontSize);
+    label->SetStyle(OHOS::STYLE_LINE_HEIGHT, config.lineHeight);
+    label->SetAlign(OHOS::TEXT_ALIGNMENT_LEFT);
+    label->SetLineBreakMode(config.lineBreakMode);
+    
+    
+    return label;
+}
 
-    void PPPTestView::OnStart()
-    {
-        printf("PPPTestView::OnStart\n");
-        InitView();
+// 更新PPP运行状态显示 - 统一格式结构
+static void update_ppp_runtime_status_display() {
+    if (!g_ppp_init_completed) {
+        return;
     }
-
-    void PPPTestView::InitView()
-    {
-        if (viewInitStatus_) {
-            printf("PPPTestView already initialized\n");
+    
+    printf("=== 更新PPP运行状态显示 ===\n");
+    
+    // 更新所有运行时状态
+    #if SUPPORT_PPP_SERVICE 
+    errcode_t ret = ppp_api_update_all_runtime_status();
+    #else
+    errcode_t ret = ERRCODE_SUCC;
+    #endif
+    if (ret != ERRCODE_SUCC) {
+        printf("更新PPP运行状态失败: %d\n", ret);
         return;
     }
     
-        printf("Initializing PPPTestView\n");
-
-        // 创建主滚动视图
-        if (scrollview_ == nullptr) {
-            scrollview_ = new UIScrollView();
-            if (scrollview_ == nullptr) {
-                printf("ERROR: Failed to create main scroll view\n");
+    // 使用malloc动态分配,避免栈溢出
+    char* buffer = (char*)malloc(200);
+    if (buffer == NULL) {
+        printf("ERROR: Failed to allocate buffer for PPP status display\n");
                 return;
             }
 
-            scrollview_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
-            scrollview_->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
-            scrollview_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR);
-            scrollview_->SetTouchable(true);
-            scrollview_->SetDraggable(true);
-            scrollview_->SetVisible(true);
-
-            // 不需要事件监听器
+    int label_index = 1; // 跳过标题,从索引1开始
+    
+    // 1. SIM卡插入状态
+    if (g_ppp_status_labels[label_index] != nullptr) {
+        int sim_stat = cat1_api_runtime_get_cat1_simstat();
+        const char* sim_desc;
+        switch(sim_stat) {
+            case 0: sim_desc = "未插入"; break;
+            case 1: sim_desc = "已插入"; break;
+            case 2: sim_desc = "被锁定"; break;
+            case 3: sim_desc = "已损坏"; break;
+            default: sim_desc = "状态未知"; break;
         }
-
-        viewInitStatus_ = true;
-        printf("PPPTestView initialized successfully\n");
+        snprintf(buffer, 200, "SIM状态: %s", sim_desc);
+        g_ppp_status_labels[label_index]->SetText(buffer);
+        g_ppp_status_labels[label_index]->SetVisible(true);
+        g_ppp_status_labels[label_index]->Invalidate();
+        printf("设置SIM状态标签[%d]: %s\n", label_index, buffer);
+        label_index++;
     }
-
-    void PPPTestView::DeInit()
-    {
-        if (!viewInitStatus_) {
-            return;
-        }
-
-        printf("Deinitializing PPPTestView\n");
-
-        // 停止测试(如果正在运行)
-        if (isTestActive_) {
-            StopPPPTest();
-        }
-
-        // 清理主视图
-        if (scrollview_ != nullptr) {
-            RootView* rootView = RootView::GetInstance();
-            if (rootView && scrollview_->GetParent() == rootView) {
-                rootView->Remove(scrollview_);
-            }
-            delete scrollview_;
-            scrollview_ = nullptr;
-        }
-
-        viewInitStatus_ = false;
+    
+    // 2. IMEI信息
+    if (g_ppp_status_labels[label_index] != nullptr) {
+        char* imei = cat1_api_runtime_get_cat1_imei();
+        snprintf(buffer, 200, "IMEI: %s", 
+                (imei && strlen(imei) > 0) ? imei : "未知");
+        g_ppp_status_labels[label_index]->SetText(buffer);
+        g_ppp_status_labels[label_index]->SetVisible(true);
+        g_ppp_status_labels[label_index]->Invalidate();
+        printf("设置IMEI标签[%d]: %s\n", label_index, buffer);
+        label_index++;
     }
-
-    void PPPTestView::PreLoad()
-    {
-        printf("PPPTestView::PreLoad\n");
-        InitView();
+    
+    // 3. ICCID信息
+    if (g_ppp_status_labels[label_index] != nullptr) {
+        char* iccid = cat1_api_runtime_get_cat1_iccid();
+        snprintf(buffer, 200, "ICCID: %s", 
+                (iccid && strlen(iccid) > 0) ? iccid : "未知");
+        g_ppp_status_labels[label_index]->SetText(buffer);
+        g_ppp_status_labels[label_index]->SetVisible(true);
+        g_ppp_status_labels[label_index]->Invalidate();
+        printf("设置ICCID标签[%d]: %s\n", label_index, buffer);
+        label_index++;
     }
-
-    void PPPTestView::StartPPPTest()
-    {
-        if (isTestActive_) {
-            printf("PPP test already active\n");
-            return;
+    
+    // 4. 版本信息 (临时屏蔽)
+    /*
+    if (g_ppp_status_labels[label_index] != nullptr) {
+        char* version = cat1_api_runtime_get_cat1_modemver();
+        if (version && strlen(version) > 0) {
+            // 使用换行符在一个标签中显示VER和版本号
+            snprintf(buffer, sizeof(buffer), "VER:\n%s", version);
+        } else {
+            snprintf(buffer, sizeof(buffer), "VER:\n未知");
         }
-
-        printf("Starting PPP test view\n");
-        
-        RootView* rootView = RootView::GetInstance();
-        if (rootView == nullptr) {
-            printf("ERROR: RootView not initialized\n");
-            return;
+        g_ppp_status_labels[label_index]->SetText(buffer);
+        label_index++;
+    }
+    */
+    
+    // 4. 信号强度信息
+    if (g_ppp_status_labels[label_index] != nullptr) {
+        int signal = cat1_api_runtime_get_cat1_signal();
+        const char* signal_desc;
+        if (signal == 99) {
+            signal_desc = "无信号";
+            snprintf(buffer, 200, "信号强度: %s", signal_desc);
+        } else {
+            // 根据信号强度分级
+            if (signal >= 20) signal_desc = "极强";
+            else if (signal >= 15) signal_desc = "强";
+            else if (signal >= 10) signal_desc = "中等";
+            else if (signal >= 5) signal_desc = "弱";
+            else signal_desc = "极弱";
+            
+            snprintf(buffer, 200, "信号强度: %d (%s)", signal, signal_desc);
         }
-        
-        // 保存当前显示的view
-        savedCurrentView_ = rootView->GetChildrenHead();
-        if (savedCurrentView_ != nullptr && savedCurrentView_ != scrollview_) {
-            rootView->Remove(savedCurrentView_);
-            printf("Saved and removed current view for later restore\n");
+        g_ppp_status_labels[label_index]->SetText(buffer);
+        g_ppp_status_labels[label_index]->SetVisible(true);
+        g_ppp_status_labels[label_index]->Invalidate();
+        printf("设置信号强度标签[%d]: %s\n", label_index, buffer);
+        label_index++;
+    }
+    
+    // 5. 网络状态信息
+    if (g_ppp_status_labels[label_index] != nullptr && label_index < 4) {
+        uint8_t network_stat = cat1_api_runtime_get_cat1_networkstat();
+        const char* network_desc;
+        switch(network_stat) {
+            case 0: network_desc = "未注册"; break;
+            case 1: network_desc = "已注册(本地网络)"; break;
+            case 2: network_desc = "搜索中"; break;
+            case 3: network_desc = "注册被拒绝"; break;
+            case 5: network_desc = "已注册(漫游)"; break;
+            default: network_desc = "未知状态"; break;
         }
-        
-        // 创建PPP测试视图
-        if (testView_ == nullptr) {
-            testView_ = new UIScrollView();
-            if (testView_ == nullptr) {
-                printf("ERROR: Failed to create PPP test view\n");
-                return;
-            }
+        snprintf(buffer, 200, "网络状态: %s", network_desc);
+        g_ppp_status_labels[label_index]->SetText(buffer);
+        g_ppp_status_labels[label_index]->SetVisible(true);
+        g_ppp_status_labels[label_index]->Invalidate();
+        printf("设置网络状态标签[%d]: %s\n", label_index, buffer);
+        label_index++;
+    }
+    
+    // 清空基本状态部分后面的剩余标签(为信号质量部分预留空间)
+    for (int i = label_index; i < 5; i++) {
+        if (g_ppp_status_labels[i] != nullptr) {
+            g_ppp_status_labels[i]->SetText("");
+            g_ppp_status_labels[i]->SetVisible(true); // 保持可见,待信号质量更新
+        }
+    }
+    
+    // 确保信号质量标签也是可见和可用的
+    for (int i = 5; i < 12; i++) {
+        if (g_ppp_status_labels[i] != nullptr) {
+            g_ppp_status_labels[i]->SetVisible(true); // 确保信号质量标签可见
         }
-        
-        SetupScrollView();
-        CreateLabels();
-        
-        // 添加到根视图
-        rootView->Add(testView_);
-        rootView->Invalidate();
-
-        isTestActive_ = true;
-        printf("PPP test started\n");
     }
+    
+    printf("PPP运行状态显示更新完成\n");
+    
+    // 释放动态分配的内存
+    free(buffer);
+}
 
-    void PPPTestView::StopPPPTest()
-    {
-        if (!isTestActive_) {
-            printf("PPP test not active\n");
+// 更新信号质量信息显示 - 统一格式结构
+static void update_signal_quality_display() {
+    if (!g_ppp_init_completed) {
             return;
         }
 
-        printf("Stopping PPP test view\n");
-        
-        RootView* rootView = RootView::GetInstance();
-        if (rootView != nullptr) {
-            // 删除PPP测试view
-            if (testView_ != nullptr) {
-                rootView->Remove(testView_);
-                DestroyLabels();
-                delete testView_;
-                testView_ = nullptr;
-                printf("PPP test view removed\n");
-            }
-            
-            // 恢复原来的view
-            if (savedCurrentView_ != nullptr) {
-                printf("Attempting to restore view at address: %p\n", savedCurrentView_);
-                
-                if (savedCurrentView_->GetParent() == nullptr) {
-                    rootView->Add(savedCurrentView_);
-                    rootView->Invalidate();
-                    printf("Original view restored successfully\n");
-                } else {
-                    printf("Warning: Original view still has parent, cannot restore\n");
-                }
-                savedCurrentView_ = nullptr;
-            } else {
-                printf("No original view to restore\n");
-            }
+    printf("=== 更新信号质量显示 ===\n");
+    
+    // 使用直接的API获取信号信息
+    ppp_network_signal_info_t signal_info;
+    #if SUPPORT_PPP_SERVICE
+    ppp_error_t ret = ppp_at_get_network_signal_info(&signal_info);
+    #else
+    ppp_error_t ret = PPP_ERR_OK;
+    // 模拟数据供测试
+    signal_info.valid = 1;
+    signal_info.rsrq = 25;  // 模拟 RSRQ 值
+    signal_info.rsrp = 45;  // 模拟 RSRP 值
+    #endif
+    
+    if (ret != PPP_ERR_OK) {
+        printf("获取信号质量信息失败: %d\n", ret);
+        // 显示错误信息
+        if (g_ppp_status_labels[5] != nullptr) {
+            g_ppp_status_labels[5]->SetText("信号质量获取失败");
+            g_ppp_status_labels[5]->SetVisible(true);
+            g_ppp_status_labels[5]->Invalidate();
         }
-
-        isTestActive_ = false;
-        currentStatus_ = PPPTestStatus::Idle;
+        return;
     }
-
-    void PPPTestView::RefreshPPPData()
-    {
-        if (!isTestActive_) {
-            printf("PPP test not active, cannot refresh\n");
+    
+    // 使用malloc动态分配,避免栈溢出
+    char* buffer = (char*)malloc(200);
+    if (buffer == NULL) {
+        printf("ERROR: Failed to allocate buffer for signal quality display\n");
             return;
         }
-
-        printf("Refreshing PPP test data display\n");
-        UpdateDisplay();
-    }
-
-    void PPPTestView::SetupScrollView()
-    {
-        if (testView_ == nullptr) return;
-        
-        // 设置PPP测试视图 - 适配360x360圆形LCD
-        testView_->SetPosition(0, 0, 360, 360);
-        testView_->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
-        testView_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR);
-        testView_->SetStyle(STYLE_BORDER_RADIUS, 0);
-        testView_->SetTouchable(true);
-        testView_->SetDraggable(true);
-        testView_->SetVisible(true);
-        testView_->SetYScrollBarVisible(true);
-        testView_->SetScrollBlankSize(30);
-        
-        // 不需要事件监听器
-    }
-
-    void PPPTestView::CreateLabels()
-    {
-        if (testView_ == nullptr) return;
-        
-        // 创建标题标签
-        PPPLabelConfig_t titleConfig = {
-            .left = 114,
-            .top = 10,
-            .width = 132,
-            .height = 28,
-            .textColor = TITLE_COLOR,
-            .fontSize = 20,
-            .text = "PPP测试"
-        };
         
-        titleLabel_ = new UILabel();
-        if (titleLabel_) {
-            titleLabel_->SetPosition(titleConfig.left, titleConfig.top, 
-                                   titleConfig.width, titleConfig.height);
-            titleLabel_->SetText(titleConfig.text);
-            titleLabel_->SetFont("SourceHanSansSC-Regular.otf", titleConfig.fontSize);
-            titleLabel_->SetStyle(STYLE_TEXT_COLOR, titleConfig.textColor);
-            titleLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER);
-            testView_->Add(titleLabel_);
+    if (!signal_info.valid) {
+        printf("信号质量信息无效\n");
+        if (g_ppp_status_labels[5] != nullptr) {
+            g_ppp_status_labels[5]->SetText("信号质量: 信息无效");
+            g_ppp_status_labels[5]->SetVisible(true);
+            g_ppp_status_labels[5]->Invalidate();
         }
-        
-        // 创建状态标签
-        const char* labelTexts[] = {
-            "状态: 初始化中...",
-            "电源: 未知",
-            "网络: 未知", 
-            "信号: 未知",
-            "SIM: 未知",
-            "网络类型: 未知",
-            "运营商: 未知",
-            "IMEI: 未知",
-            "ICCID: 未知",
-            "调制解调器: 未知",
-            "信号质量: 未知"
-        };
-        
-        for (int i = 0; i < MAX_STATUS_LABELS - 1 && i < 11; i++) {
-            statusLabels_[i] = new UILabel();
-            if (statusLabels_[i]) {
-                int yPos = 45 + (i * 32);
-                statusLabels_[i]->SetPosition(15, yPos, LABEL_WIDTH, LABEL_HEIGHT);
-                statusLabels_[i]->SetText(labelTexts[i]);
-                statusLabels_[i]->SetFont("SourceHanSansSC-Regular.otf", 16);
-                statusLabels_[i]->SetStyle(STYLE_TEXT_COLOR, TEXT_COLOR);
-                statusLabels_[i]->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT);
-                testView_->Add(statusLabels_[i]);
+        // 清空其他信号质量标签
+        for (int i = 6; i < 12; i++) {
+            if (g_ppp_status_labels[i] != nullptr) {
+                g_ppp_status_labels[i]->SetText("");
+                g_ppp_status_labels[i]->SetVisible(false);
             }
         }
+        free(buffer);
+        return;
     }
-
-    void PPPTestView::DestroyLabels()
-    {
-        if (titleLabel_) {
-            delete titleLabel_;
-            titleLabel_ = nullptr;
+    
+    int label_index = 5; // 从第5个标签开始显示信号质量信息(SIM状态已添加)
+    
+    // 检查LTE信号参数有效性
+    if (signal_info.rsrq != 255 && signal_info.rsrp != 255 && 
+        signal_info.rsrq >= 0 && signal_info.rsrq <= 49 && 
+        signal_info.rsrp >= 0 && signal_info.rsrp <= 97) {
+        
+        // 使用正确的转换公式
+        float rsrq_db = (signal_info.rsrq - 94) / 10.0f;   // (rsrq - 94)/10
+        float rsrp_dbm = signal_info.rsrp - 140.0f;        // rsrp - 140
+        
+        // RSRQ评级
+        const char* rsrq_rating;
+        if (rsrq_db >= -7.0) {
+            rsrq_rating = "极佳";
+        } else if (rsrq_db >= -12.0) {
+            rsrq_rating = "良好";
+        } else if (rsrq_db >= -19.5) {
+            rsrq_rating = "较差";
+        } else {
+            rsrq_rating = "极差";
         }
         
-        for (int i = 0; i < MAX_STATUS_LABELS; i++) {
-            if (statusLabels_[i]) {
-                delete statusLabels_[i];
-                statusLabels_[i] = nullptr;
-            }
+        // RSRP评级
+        const char* rsrp_rating;
+        if (rsrp_dbm >= -85) {
+            rsrp_rating = "极好";
+        } else if (rsrp_dbm >= -100) {
+            rsrp_rating = "良好";
+        } else if (rsrp_dbm >= -110) {
+            rsrp_rating = "较弱";
+        } else {
+            rsrp_rating = "极差";
         }
-    }
-
-    void PPPTestView::UpdateTestStatus(PPPTestStatus status)
-    {
-        currentStatus_ = status;
-        
-        if (!isTestActive_ || statusLabels_[0] == nullptr) return;
         
-        const char* statusText = "";
-        switch (status) {
-            case PPPTestStatus::Idle:
-                statusText = "状态: 空闲";
-                break;
-            case PPPTestStatus::Initializing:
-                statusText = "状态: 初始化中...";
-                break;
-            case PPPTestStatus::Testing:
-                statusText = "状态: 测试中";
-                break;
-            case PPPTestStatus::Refreshing:
-                statusText = "状态: 刷新数据中...";
-                break;
-            case PPPTestStatus::Error:
-                statusText = "状态: 错误";
-                break;
+        // 5. RSRQ信号质量信息
+        if (g_ppp_status_labels[label_index] != nullptr) {
+            snprintf(buffer, 200, "RSRQ: %d (%.1fdB) [%s]", 
+                    signal_info.rsrq, rsrq_db, rsrq_rating);
+            g_ppp_status_labels[label_index]->SetText(buffer);
+            g_ppp_status_labels[label_index]->SetVisible(true);
+            g_ppp_status_labels[label_index]->Invalidate();
+            printf("设置RSRQ标签[%d]: %s\n", label_index, buffer);
+            label_index++;
         }
         
-        statusLabels_[0]->SetText(statusText);
-        RootView::GetInstance()->Invalidate();
-    }
-
-    void PPPTestView::UpdateNetworkInfo()
-    {
-        if (!isTestActive_ || !PPPTestModel::GetInstance()) return;
-        
-        const PPPStatusInfo& info = PPPTestModel::GetInstance()->GetStatusInfo();
-        if (!info.isValid) return;
-        
-        char buffer[256];
-        
-        // 更新电源状态
-        if (statusLabels_[1]) {
-            snprintf(buffer, sizeof(buffer), "电源: %s", info.powerStatus ? "开启" : "关闭");
-            statusLabels_[1]->SetText(buffer);
+        // 6. RSRP信号强度信息
+        if (g_ppp_status_labels[label_index] != nullptr) {
+            snprintf(buffer, 200, "RSRP: %d (%.0fdBm) [%s]", 
+                    signal_info.rsrp, rsrp_dbm, rsrp_rating);
+            g_ppp_status_labels[label_index]->SetText(buffer);
+            g_ppp_status_labels[label_index]->SetVisible(true);
+            g_ppp_status_labels[label_index]->Invalidate();
+            printf("设置RSRP标签[%d]: %s\n", label_index, buffer);
+            label_index++;
         }
         
-        // 更新网络状态
-        if (statusLabels_[2]) {
-            snprintf(buffer, sizeof(buffer), "网络: %s", info.networkStatus ? "已连接" : "未连接");
-            statusLabels_[2]->SetText(buffer);
+        // 7. LTE综合信号质量评估
+        if (g_ppp_status_labels[label_index] != nullptr) {
+            const char* overall_quality;
+            // 根据RSRQ和RSRP的评级综合评估
+            if ((rsrq_db >= -7.0 && rsrp_dbm >= -85) || 
+                (rsrq_db >= -12.0 && rsrp_dbm >= -100)) {
+                overall_quality = "优秀";
+            } else if ((rsrq_db >= -12.0 && rsrp_dbm >= -110) || 
+                       (rsrq_db >= -19.5 && rsrp_dbm >= -100)) {
+                overall_quality = "良好";
+            } else if (rsrq_db >= -19.5 && rsrp_dbm >= -110) {
+                overall_quality = "一般";
+            } else {
+                overall_quality = "较差";
+            }
+            
+            snprintf(buffer, 200, "LTE综合质量: %s", overall_quality);
+            g_ppp_status_labels[label_index]->SetText(buffer);
+            g_ppp_status_labels[label_index]->SetVisible(true);
+            g_ppp_status_labels[label_index]->Invalidate();
+            printf("设置LTE综合质量标签[%d]: %s\n", label_index, buffer);
+            label_index++;
         }
         
-        // 更新信号强度
-        if (statusLabels_[3]) {
-            snprintf(buffer, sizeof(buffer), "信号: %d", info.signalStrength);
-            statusLabels_[3]->SetText(buffer);
+        // 清空剩余未使用的标签
+        for (int i = label_index; i < 12; i++) {
+            if (g_ppp_status_labels[i] != nullptr) {
+                g_ppp_status_labels[i]->SetText("");
+                g_ppp_status_labels[i]->SetVisible(false);
+            }
         }
         
-        // 更新SIM状态
-        if (statusLabels_[4]) {
-            const char* simStatus = PPPTestModel::GetInstance()->GetSimStatusName(info.simStatus);
-            snprintf(buffer, sizeof(buffer), "SIM: %s", simStatus);
-            statusLabels_[4]->SetText(buffer);
+        printf("LTE信号质量更新: RSRQ=%d(%.1fdB)[%s], RSRP=%d(%.0fdBm)[%s]\n", 
+               signal_info.rsrq, rsrq_db, rsrq_rating, signal_info.rsrp, rsrp_dbm, rsrp_rating);
+    } else {
+        // 显示无效的LTE参数
+        if (g_ppp_status_labels[label_index] != nullptr) {
+            snprintf(buffer, 200, "RSRQ: 无效数据 (%d)", signal_info.rsrq);
+            g_ppp_status_labels[label_index]->SetText(buffer);
+            g_ppp_status_labels[label_index]->SetVisible(true);
+            g_ppp_status_labels[label_index]->Invalidate();
+            printf("设置RSRQ无效标签[%d]: %s\n", label_index, buffer);
+            label_index++;
         }
-        
-        // 更新网络类型
-        if (statusLabels_[5]) {
-            const char* networkType = PPPTestModel::GetInstance()->GetNetworkTypeName(info.networkType);
-            snprintf(buffer, sizeof(buffer), "网络类型: %s", networkType);
-            statusLabels_[5]->SetText(buffer);
+        if (g_ppp_status_labels[label_index] != nullptr) {
+            snprintf(buffer, 200, "RSRP: 无效数据 (%d)", signal_info.rsrp);
+            g_ppp_status_labels[label_index]->SetText(buffer);
+            g_ppp_status_labels[label_index]->SetVisible(true);
+            g_ppp_status_labels[label_index]->Invalidate();
+            printf("设置RSRP无效标签[%d]: %s\n", label_index, buffer);
+            label_index++;
         }
-        
-        // 更新运营商
-        if (statusLabels_[6]) {
-            snprintf(buffer, sizeof(buffer), "运营商: %s", info.operatorName[0] ? info.operatorName : "未知");
-            statusLabels_[6]->SetText(buffer);
+        if (g_ppp_status_labels[label_index] != nullptr) {
+            g_ppp_status_labels[label_index]->SetText("LTE综合质量: 数据无效");
+            g_ppp_status_labels[label_index]->SetVisible(true);
+            g_ppp_status_labels[label_index]->Invalidate();
+            label_index++;
         }
         
-        RootView::GetInstance()->Invalidate();
+        printf("LTE参数无效: RSRQ=%d, RSRP=%d\n", signal_info.rsrq, signal_info.rsrp);
     }
+    
+    // 清空剩余未使用的标签
+    for (int i = label_index; i < 12; i++) {
+        if (g_ppp_status_labels[i] != nullptr) {
+            g_ppp_status_labels[i]->SetText("");
+            g_ppp_status_labels[i]->SetVisible(false);
+        }
+    }
+    
+    printf("信号质量显示更新完成\n");
+    
+    // 释放动态分配的内存
+    free(buffer);
+}
 
-    void PPPTestView::UpdateSignalInfo()
-    {
-        if (!isTestActive_ || !PPPTestModel::GetInstance()) return;
-        
-        const PPPSignalInfo& info = PPPTestModel::GetInstance()->GetSignalInfo();
-        if (!info.isValid) return;
-        
-        char buffer[256];
+// 全局变量,避免栈溢出
+static int g_consecutive_failures = 0;
+
+// 全局刷新标志,避免在定时器回调中直接操作UI
+static volatile bool g_need_refresh = false;
+
+// UI刷新回调函数 - 通过GraphicEvent在主UI线程中安全执行,避免栈溢出
+static void ppp_refresh_ui_callback(void* userData) {
+    (void)userData; // 未使用的参数
+    
+    if (!g_ppp_init_completed || g_ppp_test_view == nullptr) {
+        return; // 如果PPP未初始化完成或view已销毁,不执行刷新
+    }
+    
+    // 每次UI刷新时重新设置屏幕常亮,防止被其他程序覆盖
+    uapi_set_screen_on_api();
+    ScreenAlwaysOnCtr(1);
+    
+    printf("PPP UI刷新开始 - GraphicEvent安全机制\n");
+    
+    // 使用malloc为buffer分配内存,避免栈溢出
+    char* buffer = (char*)malloc(512);
+    if (buffer == nullptr) {
+        printf("ERROR: malloc失败,跳过此次刷新\n");
+        return;
+    }
+    
+    // 安全地更新运行状态显示
+    update_ppp_runtime_status_display();
+    
+    // 尝试获取信号质量,但增加容错机制
+    #if SUPPORT_PPP_SERVICE
+    errcode_t ret = ppp_get_network_signal_info();
+    #else
+    errcode_t ret = ERRCODE_SUCC;
+    #endif
+    if (ret == ERRCODE_SUCC) {
+        g_consecutive_failures = 0; // 重置失败计数
+        update_signal_quality_display();
+        printf("PPP信号质量更新成功\n");
+    } else {
+        g_consecutive_failures++;
+        printf("PPP信号质量获取失败 (%d次)\n", g_consecutive_failures);
         
-        // 更新信号质量
-        if (statusLabels_[10]) {
-            if (info.rsrq != -1 && info.rsrp != -1) {
-                const char* levelName = PPPTestModel::GetInstance()->GetSignalLevelName(info.level);
-                snprintf(buffer, sizeof(buffer), "信号质量: RSRQ=%d RSRP=%d (%s)", 
-                        info.rsrq, info.rsrp, levelName);
-            } else {
-                snprintf(buffer, sizeof(buffer), "信号质量: 基本信号=%d", info.rxlev);
+        // 如果连续失败超过3次,暂停信号质量查询,只更新基本状态
+        if (g_consecutive_failures >= 3) {
+            if (g_ppp_status_labels[5] != nullptr) {
+                g_ppp_status_labels[5]->SetText("信号查询暂停");
+            }
+            if (g_ppp_status_labels[6] != nullptr) {
+                g_ppp_status_labels[6]->SetText("(定时器冲突)");
             }
-            statusLabels_[10]->SetText(buffer);
         }
-        
-        RootView::GetInstance()->Invalidate();
     }
+    
+    // 释放临时buffer
+    free(buffer);
+    
+    // 刷新UI显示
+    OHOS::RootView::GetInstance()->Invalidate();
+    printf("PPP UI刷新完成\n");
+}
 
-    void PPPTestView::UpdateModemInfo()
-    {
-        if (!isTestActive_ || !PPPTestModel::GetInstance()) return;
-        
-        const PPPStatusInfo& info = PPPTestModel::GetInstance()->GetStatusInfo();
-        if (!info.isValid) return;
-        
-        char buffer[256];
-        
-        // 更新IMEI
-        if (statusLabels_[7]) {
-            snprintf(buffer, sizeof(buffer), "IMEI: %s", info.imei[0] ? info.imei : "未知");
-            statusLabels_[7]->SetText(buffer);
+// PPP刷新定时器回调函数 - 使用GraphicEvent避免栈溢出
+static void ppp_refresh_timer_callback(void *arg) {
+    (void)arg;
+    
+    if (!g_ppp_init_completed || g_ppp_test_view == nullptr) {
+        return; // 如果PPP未初始化完成或view已销毁,不执行刷新
+    }
+    
+    // 使用GraphicEvent将UI更新操作投递到主UI线程,避免栈溢出
+    // UIKit版本: 参数为 回调函数, 用户数据(NULL)
+    PostGraphicEvent(ppp_refresh_ui_callback, NULL);
+    
+    printf("PPP定时器回调 - 已投递GraphicEvent\n");
+}
+
+// 启动PPP刷新定时器
+static void start_ppp_refresh_timer() {
+    if (g_ppp_refresh_timer == NULL) {
+        g_ppp_refresh_timer = osTimerNew(ppp_refresh_timer_callback, osTimerPeriodic, NULL, NULL);
+        if (g_ppp_refresh_timer == NULL) {
+            printf("ERROR: Failed to create PPP refresh timer\n");
+            return;
         }
+    }
+    
+    // 启动5秒周期定时器
+    osTimerStart(g_ppp_refresh_timer, PPP_REFRESH_INTERVAL_MS);
+    printf("PPP刷新定时器启动 (5秒周期,避免定时器冲突)\n");
+}
+
+// 停止PPP刷新定时器
+static void stop_ppp_refresh_timer() {
+    if (g_ppp_refresh_timer != NULL) {
+        osTimerStop(g_ppp_refresh_timer);
+        osTimerDelete(g_ppp_refresh_timer);
+        g_ppp_refresh_timer = NULL;
+        printf("PPP刷新定时器停止\n");
+    }
+}
+
+// PPP初始化定时器回调函数
+static void ppp_init_timer_callback(void *arg) {
+    (void)arg;
+    
+    printf("=== PPP初始化超时,准备重试 ===\n");
+    
+    if (g_ppp_init_retry_count >= MAX_PPP_INIT_RETRIES) {
+        printf("PPP初始化达到最大重试次数(%d),停止重试\n", MAX_PPP_INIT_RETRIES);
+        g_ppp_init_in_progress = false;
         
-        // 更新ICCID
-        if (statusLabels_[8]) {
-            snprintf(buffer, sizeof(buffer), "ICCID: %s", info.iccid[0] ? info.iccid : "未知");
-            statusLabels_[8]->SetText(buffer);
+        // 简化状态显示,避免在回调中进行复杂UI操作
+        if (g_ppp_status_labels[1] != nullptr) {
+            g_ppp_status_labels[1]->SetText("PPP初始化失败");
         }
-        
-        // 更新调制解调器版本
-        if (statusLabels_[9]) {
-            snprintf(buffer, sizeof(buffer), "调制解调器: %s", 
-                    info.modemVersion[0] ? info.modemVersion : "未知");
-            statusLabels_[9]->SetText(buffer);
+        return;
+    }
+    
+    // 增加重试计数
+    g_ppp_init_retry_count++;
+    printf("开始第%d次PPP初始化重试\n", g_ppp_init_retry_count);
+    
+    // 简化状态显示
+    if (g_ppp_status_labels[1] != nullptr) {
+        g_ppp_status_labels[1]->SetText("PPP初始化重试中...");
+    }
+    
+    // 重新开始PPP初始化
+    printf("执行ppp_env_init (重试)...\n");
+    int init_ret = ppp_env_init();
+    if (init_ret == 0) {
+        printf("PPP环境初始化成功 (重试第%d次)\n", g_ppp_init_retry_count);
+        g_ppp_init_completed = true;
+        g_ppp_init_in_progress = false;
+        
+        // PPP初始化成功后重新设置屏幕常亮
+        uapi_set_screen_on_api();
+        ScreenAlwaysOnCtr(1);
+        printf("PPP初始化成功 - 屏幕常亮已重新设置\n");
+        
+        // 停止定时器
+        if (g_ppp_init_timer != NULL) {
+            osTimerStop(g_ppp_init_timer);
         }
         
-        RootView::GetInstance()->Invalidate();
-    }
-
-    void PPPTestView::ShowInitProgress(int progress)
-    {
-        if (!isTestActive_ || statusLabels_[0] == nullptr) return;
+        // 启动5秒刷新定时器(重试成功)
+        start_ppp_refresh_timer();
         
-        char buffer[64];
-        snprintf(buffer, sizeof(buffer), "状态: 初始化中... %d%%", progress);
-        statusLabels_[0]->SetText(buffer);
-        RootView::GetInstance()->Invalidate();
-    }
-
-    void PPPTestView::ShowErrorMessage(const char* error)
-    {
-        if (!isTestActive_ || statusLabels_[0] == nullptr) return;
+        // 设置刷新标志,让主线程安全处理UI更新
+        g_need_refresh = true;
+    } else {
+        printf("PPP环境初始化失败 (重试第%d次): %d\n", g_ppp_init_retry_count, init_ret);
         
-        char buffer[128];
-        snprintf(buffer, sizeof(buffer), "状态: 错误 - %s", error ? error : "未知错误");
-        statusLabels_[0]->SetText(buffer);
-        RootView::GetInstance()->Invalidate();
+        // 重新启动定时器,等待下次重试
+        if (g_ppp_init_timer != NULL) {
+            osTimerStart(g_ppp_init_timer, PPP_INIT_TIMEOUT_MS);
+        }
     }
+}
 
-    void PPPTestView::UpdateDisplay()
-    {
-        UpdateNetworkInfo();
-        UpdateSignalInfo();
-        UpdateModemInfo();
+// 启动PPP初始化和定时器
+static void start_ppp_init_with_timer() {
+    printf("=== 启动PPP初始化和定时器 ===\n");
+    
+    // 重置状态
+    g_ppp_init_completed = false;
+    g_ppp_init_in_progress = true;
+    g_ppp_init_retry_count = 0;
+    
+    // 创建定时器
+    if (g_ppp_init_timer == NULL) {
+        g_ppp_init_timer = osTimerNew(ppp_init_timer_callback, osTimerOnce, NULL, NULL);
+        if (g_ppp_init_timer == NULL) {
+            printf("ERROR: Failed to create PPP init timer\n");
+            return;
+        }
     }
-
-    UILabel* PPPTestView::GetStatusLabel(int index)
-    {
-        if (index >= 0 && index < MAX_STATUS_LABELS) {
-            return statusLabels_[index];
+    
+    // 开始PPP初始化
+    printf("执行ppp_env_init...\n");
+    int init_ret = ppp_env_init();
+    if (init_ret == 0) {
+        printf("PPP环境初始化成功\n");
+        g_ppp_init_completed = true;
+        g_ppp_init_in_progress = false;
+        
+        // PPP初始化成功后设置屏幕常亮
+        uapi_set_screen_on_api();
+        ScreenAlwaysOnCtr(1);
+        printf("PPP初始化成功 - 屏幕常亮已设置\n");
+        
+        // 启动5秒刷新定时器
+        start_ppp_refresh_timer();
+        
+        // 设置刷新标志,让主线程安全处理UI更新
+        g_need_refresh = true;
+    } else {
+        printf("PPP环境初始化失败: %d,启动定时器等待重试\n", init_ret);
+        
+        // 更新状态显示
+        if (g_ppp_status_labels[1] != nullptr) {
+            g_ppp_status_labels[1]->SetText("PPP初始化失败,5秒后重试...");
         }
-        return nullptr;
+        
+        // 启动定时器
+        osTimerStart(g_ppp_init_timer, PPP_INIT_TIMEOUT_MS);
     }
+}
 
-} // namespace OHOS
-
-// 保持向后兼容的C接口
-#ifdef __cplusplus
-#if __cplusplus
-extern "C"
-{
-#endif /* __cplusplus */
-#endif /* __cplusplus */
+extern "C" {
 
 /**
  * @brief 启动PPP测试视图
  */
 void start_ppp_test_view(void)
 {
-    OHOS::PPPTestPresenter* presenter = OHOS::PPPTestPresenter::GetInstance();
-    if (presenter) {
-        presenter->StartPPPTest();
+    printf("=== 启动PPP测试 ===\n");
+    
+    // 进入PPP界面时设置屏幕常亮
+    uapi_set_screen_on_api();
+    ScreenAlwaysOnCtr(1);
+    printf("PPP test view: Screen always on enabled\n");
+    
+    OHOS::RootView* rootView = OHOS::RootView::GetInstance();
+    if (rootView == nullptr) {
+        printf("ERROR: RootView not initialized\n");
+        return;
+    }
+    
+    // 保存当前显示的view
+    g_ppp_saved_view = rootView->GetChildrenHead();
+    if (g_ppp_saved_view != nullptr) {
+        rootView->Remove(g_ppp_saved_view);
+        printf("Saved and removed current view for later restore\n");
+    }
+    
+    // 创建ScrollView用于PPP测试
+    g_ppp_test_view = new OHOS::UIScrollView();
+    if (g_ppp_test_view == nullptr) {
+        printf("ERROR: Failed to create PPP test view\n");
+        return;
+    }
+    
+    // 设置PPP测试视图 - 适配360x360圆形LCD,支持大字体滚动
+    g_ppp_test_view->SetPosition(0, 0, 360, 360);
+    g_ppp_test_view->SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0xff);
+    g_ppp_test_view->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff000000); // 黑色背景
+    g_ppp_test_view->SetStyle(OHOS::STYLE_BORDER_RADIUS, 0);
+    g_ppp_test_view->SetTouchable(true);
+    g_ppp_test_view->SetDraggable(true);
+    g_ppp_test_view->SetVisible(true);
+    g_ppp_test_view->SetYScrollBarVisible(true);
+    g_ppp_test_view->SetScrollBlankSize(30); // 增加滚动空白,适应大字体
+    
+    // 创建标题标签 - 统一格式结构
+    PPPLabelConfig_t titleConfig = {
+        .left = 120,      // 居中位置优化
+        .top = 15,       // 顶部留白统一
+        .width = 280,    // 标题宽度统一
+        .height = 32,    // 标题高度统一
+        .fontSize = 18,  // 标题字体大小
+        .lineHeight = 32,// 行高与标签高度一致
+        .text = "PPP网络测试",
+        .lineBreakMode = OHOS::UILabel::LINE_BREAK_ADAPT
+    };
+    g_ppp_title_label = create_ppp_label(titleConfig);
+    if (g_ppp_title_label != nullptr) {
+        g_ppp_status_labels[0] = g_ppp_title_label;
+        
+        // 设置标题样式 - 统一格式结构
+        g_ppp_title_label->SetAlign(OHOS::TEXT_ALIGNMENT_CENTER);
+        g_ppp_title_label->SetStyle(OHOS::STYLE_TEXT_COLOR, 0xFF00FF00); // 绿色标题
+        g_ppp_title_label->SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0);      // 透明背景
+        g_ppp_title_label->SetVisible(true);
+        g_ppp_title_label->Invalidate();
+        
+        g_ppp_test_view->Add(g_ppp_title_label);
+        printf("PPP标题标签创建成功: 位置(%d,%d) 尺寸(%dx%d) 文字='%s'\n", 
+               titleConfig.left, titleConfig.top, titleConfig.width, titleConfig.height, titleConfig.text);
     } else {
-        printf("ERROR: PPPTestPresenter not initialized\n");
+        printf("ERROR: PPP标题标签创建失败\n");
+    }
+    
+    // 创建状态显示标签 - 统一格式结构
+    int y_start = 65;       // 标题高度32px + top 15px + 间距 18px = 65px
+    int label_height = 28;  // 标签高度统一
+    int label_spacing = 32; // 标签间距统一
+    
+    for (int i = 1; i < 12; i++) {
+        // 为不同类型标签设置不同的初始文本
+        const char* initial_text;
+        if (i <= 5) {
+            initial_text = "初始化中...";  // 基本信息标签(1-5): SIM状态、IMEI、ICCID、信号强度、网络状态
+        } else {
+            initial_text = "";              // 信号质量标签初始为空(6-11)
+        }
+        
+        PPPLabelConfig_t labelConfig = {
+            .left = 25,      // 左边距统一
+            .top = y_start + (i - 1) * label_spacing,
+            .width = 310,    // 标签宽度统一
+            .height = label_height,
+            .fontSize = 14,  // 内容字体大小
+            .lineHeight = label_height,
+            .text = initial_text,
+            .lineBreakMode = OHOS::UILabel::LINE_BREAK_WRAP
+        };
+        
+        g_ppp_status_labels[i] = create_ppp_label(labelConfig);
+        if (g_ppp_status_labels[i] != nullptr) {
+            g_ppp_test_view->Add(g_ppp_status_labels[i]);
+        }
     }
+    
+    // 添加到根视图
+    rootView->Add(g_ppp_test_view);
+    rootView->Invalidate();
+    
+    printf("PPP test view created, starting initialization with timer...\n");
+    
+    // 使用定时器启动PPP初始化
+    start_ppp_init_with_timer();
 }
 
 /**
@@ -504,29 +807,83 @@ void start_ppp_test_view(void)
  */
 void stop_ppp_test_view(void)
 {
-    OHOS::PPPTestPresenter* presenter = OHOS::PPPTestPresenter::GetInstance();
-    if (presenter) {
-        presenter->StopPPPTest();
+    printf("=== 停止PPP测试 ===\n");
+    
+    // 退出PPP界面时恢复屏幕的正常状态
+    ScreenAlwaysOnCtr(0);
+    printf("PPP test view: Screen always on disabled\n");
+    
+    OHOS::RootView* rootView = OHOS::RootView::GetInstance();
+    if (rootView != nullptr) {
+        // 停止并删除定时器
+        if (g_ppp_init_timer != NULL) {
+            osTimerStop(g_ppp_init_timer);
+            osTimerDelete(g_ppp_init_timer);
+            g_ppp_init_timer = NULL;
+            printf("PPP init timer stopped and deleted\n");
+        }
+        
+        // 停止刷新定时器
+        stop_ppp_refresh_timer();
+        
+        // 删除PPP测试view
+        if (g_ppp_test_view != nullptr) {
+            rootView->Remove(g_ppp_test_view);
+            
+            // 清理所有标签
+            for (int i = 0; i < 12; i++) {
+                if (g_ppp_status_labels[i] != nullptr) {
+                    delete g_ppp_status_labels[i];
+                    g_ppp_status_labels[i] = nullptr;
+                }
+            }
+            g_ppp_title_label = nullptr;
+            
+            delete g_ppp_test_view;
+            g_ppp_test_view = nullptr;
+            printf("PPP test view removed\n");
+        }
+        
+        // 恢复原来的view
+        if (g_ppp_saved_view != nullptr) {
+            printf("Attempting to restore view at address: %p\n", g_ppp_saved_view);
+            
+            if (g_ppp_saved_view->GetParent() == nullptr) {
+                rootView->Add(g_ppp_saved_view);
+                rootView->Invalidate();
+                printf("Original view restored successfully\n");
             } else {
-        printf("ERROR: PPPTestPresenter not initialized\n");
+                printf("Warning: Original view still has parent, cannot restore\n");
+            }
+            g_ppp_saved_view = nullptr;
+        } else {
+            printf("No original view to restore\n");
+        }
     }
+    
+    // 重置PPP状态变量
+    g_ppp_init_completed = false;
+    g_ppp_init_in_progress = false;
+    g_ppp_init_retry_count = 0;
 }
 
 /**
- * @brief 刷新PPP测试数据
+ * @brief 刷新PPP测试数据 - 安全版本,检查定时器刷新请求
  */
 void refresh_ppp_test_data(void)
 {
-    OHOS::PPPTestPresenter* presenter = OHOS::PPPTestPresenter::GetInstance();
-    if (presenter) {
-        presenter->RefreshPPPData();
-    } else {
-        printf("ERROR: PPPTestPresenter not initialized\n");
+    printf("=== 刷新PPP测试数据(手动) ===\n");
+    
+    if (!g_ppp_init_completed || g_ppp_test_view == nullptr) {
+        printf("PPP未初始化或view已销毁,无法刷新数据\n");
+        return;
     }
+    
+    // 使用GraphicEvent进行安全的UI刷新,避免栈溢出  
+    // UIKit版本: 参数为 回调函数, 用户数据(NULL)
+    PostGraphicEvent(ppp_refresh_ui_callback, NULL);
+    
+    printf("PPP手动刷新请求已发送到GraphicEvent队列\n");
 }
 
-#ifdef __cplusplus
-#if __cplusplus
-}
-#endif /* __cplusplus */
-#endif /* __cplusplus */
+} // extern "C"
index 8c4f50f..d7d1184 100644 (file)
@@ -620,33 +620,43 @@ void a5133_demo_msg_change_callback(void)
 
 #ifdef BOARD_LEINIAO
 
-static uint8_t k2_flag = 0;
-static uint8_t k3_flag = 0;
+// static uint8_t k2_flag = 0;
+// static uint8_t k3_flag = 0;
+
+#define KEY2 S_AGPIO_L12
+#define KEY3 S_AGPIO_L28
 
 static void key2_enter_ppp_testView_callback(void)
 {
     printf("111 key2_enter_ppp_testView_callback\n");
-    k2_flag = 1;
-    if(k3_flag && k2_flag)
-    {
-        printf("222 key2_enter_ppp_testView_callback\n");
+
+    if(uapi_gpio_get_val(KEY3) == GPIO_LEVEL_LOW)
         start_ppp_test_view();
-        k2_flag = 0;
-        k3_flag = 0;
-    }
+
+    // k2_flag = 1;
+    // if(k3_flag && k2_flag)
+    // {
+    //     printf("222 key2_enter_ppp_testView_callback\n");
+    //     start_ppp_test_view();
+    //     k2_flag = 0;
+    //     k3_flag = 0;
+    // }
 }
 
 static void key3_enter_ppp_testView_callback(void)
 {
     printf("111 key3_enter_ppp_testView_callback\n");
-    k3_flag = 1;
-    if(k3_flag && k2_flag)
-    {
-        printf("222 key3_enter_ppp_testView_callback\n");
+
+    if(uapi_gpio_get_val(KEY2) == GPIO_LEVEL_LOW)
         start_ppp_test_view();
-        k2_flag = 0;
-        k3_flag = 0;
-    }
+    // k3_flag = 1;
+    // if(k3_flag && k2_flag)
+    // {
+    //     printf("222 key3_enter_ppp_testView_callback\n");
+    //     start_ppp_test_view();
+    //     k2_flag = 0;
+    //     k3_flag = 0;
+    // }
 }
 
 #endif