增加低电量关机(待验证)
authorxue <2144439972@qq.com>
Sun, 2 Nov 2025 07:09:26 +0000 (15:09 +0800)
committerxue <2144439972@qq.com>
Sun, 2 Nov 2025 07:09:26 +0000 (15:09 +0800)
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdReminderView.h
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdReminderView.cpp
code/sdk/application/wearable/ln/service/msg_center/CMakeLists.txt
code/sdk/application/wearable/ln/service/msg_center/src/msg_center_customer.cpp
code/sdk/zhihui/utils/custom_utils_at_cmd.c

index 332d09f..0f82ff7 100644 (file)
@@ -336,6 +336,8 @@ namespace OHOS
         std::string m_currentStatusText;    // 当前状态文本
         std::string m_dialogueExpression;   // 对话界面表情状态
 
+        bool close_battery_flag = false;    // 电量过低即将关机标志位
+
         int downloadFileType = -1;
     };
 }
index 8aa8798..11158e8 100644 (file)
@@ -40,6 +40,7 @@ namespace OHOS
             THUNDERBIRD_REMINDERVIEW_DIALOGUE_USE_UP,   //对话用尽
             THUNDERBIRD_REMINDERVIEW_FLOW_NOT_ENOUGH,  //流量不足
             THUNDERBIRD_REMINDERVIEW_FLOW_USE_UP,      //流量用尽
+            THUNDERBIRD_REMINDERVIEW_CLOSE_BATTERY,    //电量过低即将关机
         };
 
     private:
index 8a5ef02..2382ca6 100644 (file)
  #include "wearable_log.h"
  #include <sys/time.h>
  #include <service/graphic_service.h>
- #include "custom_utils.h"
- #include <string.h>
- #include <algorithm>
- #include <ctime>
- #include "custom_runtime.h"
+#include "custom_utils.h"
+#include <string.h>
+#include <algorithm>
+#include <ctime>
+#include "custom_runtime.h"
+#ifdef SUPPORT_BATTERY_SERVICE
+#include "battery_hal.h"
+#endif
  #include "ln_api.h"
  #include "kv_store.h"
  #include "power_display_service.h"
 #include "AppViewIDs.h"
+#include "NativeAbility.h"
 #include "NativeRegisterManager.h"
 #include "graphic_service_wrapper.h"
 #include "cJSON.h"
          }
          WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "目前绑定状态 %s", temp);
 
-         uapi_setScreenDuration(30000);//自动息屏30秒
+         // uapi_setScreenDuration(30000);//自动息屏30秒
          Readlocalconfig();
 
          printf("  eyesShape_ = %s", eyesShape_.c_str());
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StartReminderHideTimer: intervalMs=%u", intervalMs);
         
+        // 如果已经有倒计时在进行,先停止并隐藏上一次的提醒
+        if (m_reminderHideActive) {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StartReminderHideTimer: Previous timer active, hiding previous reminder");
+            auto *reminder = ThunderBirdReminderView::GetInstance();
+            if (reminder != nullptr) {
+                reminder->HideAll();
+            }
+            // 重置之前的倒计时状态
+            m_reminderHideActive = false;
+            //close_battery_flag = false;
+        }
+        
         // 设置提醒隐藏定时器状态
         m_reminderHideActive = true;
         m_reminderHideTime = intervalMs / 1000; // 转换为秒数
-        
-        // 先隐藏全部提醒界面
-         auto *reminder = ThunderBirdReminderView::GetInstance();
+        if(m_reminderHideTime == 5)//电量过低即将关机提醒
+        close_battery_flag = true;
+
+        // 隐藏全部提醒界面,准备显示新的
+        auto *reminder = ThunderBirdReminderView::GetInstance();
         if (reminder != nullptr) {
-             reminder->HideAll();
-         }
+            reminder->HideAll();
+        }
         
         // 确保时间显示定时器正在运行
         if (m_timeDisplayTimer == nullptr) {
             StartTimeDisplayTimer(1000); // 1秒间隔
         }
         
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reminder hide timer started: %d seconds", m_reminderHideTime);
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reminder hide timer started: %d seconds, close_battery_flag=%d", m_reminderHideTime, close_battery_flag);
     }
 
      // ---------------------- OTA 倒计时定时器(已整合到新定时器系统) ----------------------
         if (m_reminderHideActive) {
             if (m_reminderHideTime > 0) {
                 m_reminderHideTime--;
+                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reminder hide timer: %d seconds remaining, close_battery_flag=%d, m_reminderHideActive=%d", 
+                             m_reminderHideTime, close_battery_flag, m_reminderHideActive);
             } else {
-                // 提醒隐藏时间到,隐藏所有提醒
-                auto *reminder = ThunderBirdReminderView::GetInstance();
-                if (reminder != nullptr) {
-                    reminder->HideAll();
+                            // 检查充电状态,如果充电则重置关机标志
+                #ifdef SUPPORT_BATTERY_SERVICE
+                bool isCharging = get_charge_stat() != 0;
+                if (isCharging) {
+                    if (close_battery_flag) {
+                        close_battery_flag = false;
+                        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Charging detected, clear close_battery_flag, cancel shutdown");
+                    }
+                }
+                #endif
+                // 提醒隐藏时间到
+                if (close_battery_flag) {
+                    // 关机标志为true,跳转到关机界面(和长按关机键一样)
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Switching to shutdown slice (VIEW_REBOOT), close_battery_flag=%d", close_battery_flag);
+                    m_reminderHideActive = false; // 先停止定时器
+                    close_battery_flag = false;    // 重置标志
+                    NativeAbility::GetInstance().SwitchSlice(VIEW_REBOOT);
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SwitchSlice(VIEW_REBOOT) called");
+                } else {
+                    // 正常隐藏提醒
+                    auto *reminder = ThunderBirdReminderView::GetInstance();
+                    if (reminder != nullptr) {
+                        reminder->HideAll();
+                    }
+                    m_reminderHideActive = false;
+                    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reminder hide timer completed");
                 }
-                m_reminderHideActive = false;
-                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reminder hide timer completed");
             }
         }
     }
         bool previousHasNetwork = m_hasNetwork;
         
         // 从底层API获取最新的网络状态信息
+        #ifdef SUPPORT_CAT1_SERVICE
         m_simStatus = uapi_dev_runtime_get_cat1_simstat();           // SIM卡状态
         m_cat1PowerStatus = uapi_dev_runtime_get_cat1_powerstat();   // CAT1电源状态
         m_signalStrength = uapi_dev_runtime_get_cat1_signal();       // 信号强度
         m_networkStatus = uapi_dev_runtime_get_cat1_networkstat();   // 网络连接状态
         m_networkType = uapi_dev_runtime_get_cat1_networtype();      // 网络类型
+        #endif
         
         // 更新网络连接标志位:m_networkStatus == 1表示有网络连接
         m_hasNetwork = (m_networkStatus == 1);
index f3d2e3f..6131799 100644 (file)
@@ -245,7 +245,7 @@ namespace OHOS
             {
                 RemindButton->SetText("电量不足5%");
             }
-            }
+          }
 
             break;
         }
@@ -406,6 +406,18 @@ namespace OHOS
             }
             break;
         }
+        case THUNDERBIRD_REMINDERVIEW_CLOSE_BATTERY:
+        {
+            if (RemindButton)
+            {
+                RemindButton->SetPosition(87, 114, 185, 40);
+                RemindButton->SetText("电量过低即将关机");
+                RemindButton->SetLabelPosition(0, 0);
+                RemindButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20);
+                RemindButton->SetVisible(true);
+            }
+            break;
+        }
         default:
             break;
         }
index 4eca4ab..6436edf 100644 (file)
@@ -100,6 +100,7 @@ set(PUBLIC_HEADER
 
 set(PRIVATE_HEADER
     ${CMAKE_CURRENT_SOURCE_DIR}/../../nativeapp/nativelauncher/include
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../nativeapp/nativeui
     ${CMAKE_CURRENT_SOURCE_DIR}/../../ohos_deps
     ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/include
     ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/utils/innerkits
@@ -110,6 +111,7 @@ set(PRIVATE_HEADER
     ${ROOT_DIR}/middleware/services/gui/uikit/surface/interfaces/kits
     ${ROOT_DIR}/middleware/services/gui/uikit/ui/frameworks
     ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components_ext
+    ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/kits/components
     ${ROOT_DIR}/open_source/openharmony/foundation/multimedia/audio_player/interfaces/kits
     ${ROOT_DIR}/open_source/openharmony/foundation/multimedia/audiomanager/interfaces/kits/audiomanager
     ${ROOT_DIR}/open_source/openharmony/foundation/multimedia/audiomanager/interfaces/kits/audiocommon
@@ -123,6 +125,7 @@ set(PRIVATE_HEADER
     ${ROOT_DIR}/application/auto_ota
     ${ROOT_DIR}/application/wearable/service/xiaodu_navi_vector
     ${ROOT_DIR}/open_source/openharmony/third_party/cJSON
+    ${ROOT_DIR}/open_source/openharmony/third_party/qrcodegen/cpp
     ${ROOT_DIR}/application/wearable/service/device_msg
     ${ROOT_DIR}/application/wearable/service/msg_center/src/notify/ketinput/include
     ${ROOT_DIR}/application/wearable/nativeapp/nativelauncher/include
index 21a5745..b923914 100644 (file)
 #include "cJSON.h"
 #include "heartrate/HeartModel.h"
 #include "device_location.h"
+#include "thunderbird/include/ThunderBirdReminderView.h"
+#include "thunderbird/include/ThunderBirdMainView.h"
+#if defined(SUPPORT_POWER_MANAGER)
+#include "power_display_service.h"
+#endif
 namespace OHOS {
 
 #ifdef __cplusplus
@@ -359,6 +364,97 @@ void MsgCenterNotifyDebugOutProc(const Topic topic, Request* req)
     }
 }
 
+void MsgCenterNotifyLowpowerProc(const Topic topic, Request* req)
+{
+    WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyProc:: LowPower Alarm !");
+    #if defined(SUPPORT_POWER_MANAGER)
+    if (req == nullptr || req->data == nullptr || req->len < sizeof(uint8_t)) {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyLowpowerProc: invalid request data, req=%p, data=%p, len=%d", 
+                     req, req ? req->data : nullptr, req ? req->len : 0);
+        return;
+    }
+    
+    uint8_t *x= (uint8_t *)(req->data);
+    uint8_t alarm_type = *x;
+    WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyLowpowerProc: alarm_type=%d", alarm_type);
+    
+    const power_display_svr_api_t *display_api = power_display_svr_get_api();
+    
+    if (display_api == nullptr) {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyLowpowerProc: display_api is null");
+        return;
+    }
+    
+    // 检查函数指针是否有效
+    if (display_api->get_screen_state == nullptr || 
+        display_api->turn_on_screen == nullptr || 
+        display_api->set_screen_set_keepon_timeout == nullptr) {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyLowpowerProc: display_api function pointers are invalid");
+        return;
+    }
+ 
+    if(alarm_type == 3)
+    {
+        if (display_api->get_screen_state() != SCREEN_ON)
+        {   
+            display_api->turn_on_screen();  
+        }
+        display_api->set_screen_set_keepon_timeout(1000*5);
+        // 切换到提醒界面
+        ThunderBirdMainView *mainView = ThunderBirdMainView::GetInstance();
+        if (mainView != nullptr) {
+            ThunderBirdModel::GetInstance()->StartReminderHideTimer(5000);
+            mainView->ChangeThunderBirdReminderView(THUNDERBIRD_REMINDERVIEW); // 不走ChangeView
+            ThunderBirdReminderView *reminderView = ThunderBirdReminderView::GetInstance();
+            if (reminderView != nullptr)
+            {
+                reminderView->Show(ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_CLOSE_BATTERY);
+            }
+        } else {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyLowpowerProc: ThunderBirdMainView::GetInstance() returned null");
+        }
+    }
+    else if(alarm_type == 0)
+    {
+        //提醒低电充电
+         if (display_api->get_screen_state() != SCREEN_ON)
+        {   
+            display_api->turn_on_screen();  
+        }
+        display_api->set_screen_set_keepon_timeout(1000*5);
+
+        // set_lowpower_falg(0);  // TODO: 函数未实现,暂时注释
+        if (CheckPriority(topic))
+        {
+            NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO);
+            NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true);
+        }
+    }
+    else
+    {
+        //电量过低,直接提醒关机
+        if (display_api->get_screen_state() != SCREEN_ON)
+        {   
+            display_api->turn_on_screen();  
+        }
+        display_api->set_screen_set_keepon_timeout(1000*10);
+        
+        // set_lowpower_falg(1);  // TODO: 函数未实现,暂时注释
+        if (NotificationManager::GetInstance()->HasNotifyShowing())
+        NotificationManager::GetInstance()->StopNotify();
+        if (CheckPriority(topic))
+        {
+        NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_ONE);
+        NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true);
+        }
+        }
+    #else
+    unused(topic);
+    unused(req);
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyLowpowerProc: SUPPORT_POWER_MANAGER not defined");
+    #endif
+}
+
 
 /* 订阅事件通知逻辑可定制 */
 static MsgCenterNotifyTable g_msgCenterNotifyTable[] = {
@@ -377,6 +473,7 @@ static MsgCenterNotifyTable g_msgCenterNotifyTable[] = {
     {TOPIC_EVENT_BLOODOXYGEN_UPDATA, MsgCenterNotifyBloodOxygenProc},
     {TOPIC_EVENT_SPORT_DISTANCE,     MsgCenterNotifyDistanceProc},
     {TOPIC_EVENT_LOCATION,           MsgCenterNotifyLocationProc},
+    {TOPIC_EVENT_LOWPOWER_ALARM,     MsgCenterNotifyLowpowerProc},
     {TOPIC_EVENT_DEBUGOUTPUT,           MsgCenterNotifyDebugOutProc},
 };
 
index f3e676f..83c21f4 100644 (file)
@@ -1858,6 +1858,46 @@ static uint32_t custom_get_btmac(uint8_t *para, uint32_t paraLen, char *strCommo
 
 
 
+// AT指令:触发低电量通知测试
+// 用法:AT^LOWPOWER=0 (提醒低电充电)
+//       AT^LOWPOWER=1 (电量过低,直接提醒关机)
+//       AT^LOWPOWER=3 (倒计时结束后,直接执行关机动画)
+static uint32_t custom_lowpower_alarm_test(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+    UNUSED(strCommonCmd);
+    uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 };
+    uint32_t argc = 0;
+
+    int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
+    if (ret != CUSTOM_UTILS_SUCCESS) {
+        wstp_print("LOWPOWER ATCMD Convert Command Failed\n");
+        return ERRCODE_FAIL;
+    }
+
+    if (argc != 1) {
+        wstp_print("LOWPOWER ATCMD Set Parameter Failed argc %d\n", argc);
+        wstp_print("Usage: AT^LOWPOWER=0 (提醒低电充电)\n");
+        wstp_print("       AT^LOWPOWER=1 (电量过低,直接提醒关机)\n");
+        wstp_print("       AT^LOWPOWER=3 (倒计时结束后,直接执行关机动画)\n");
+        return ERRCODE_FAIL;
+    }
+
+    uint8_t alarm_type = (uint8_t)atoi((char *)argv[0]);
+    
+    // 验证参数范围
+    if (alarm_type != 0 && alarm_type != 1 && alarm_type != 3) {
+        wstp_print("LOWPOWER ATCMD Invalid parameter: %d (must be 0, 1, or 3)\n", alarm_type);
+        return ERRCODE_FAIL;
+    }
+
+    wstp_print("LOWPOWER ATCMD Trigger low power alarm, type=%d\n", alarm_type);
+    
+    // 发布低电量通知事件
+    CustomEventPublish(TOPIC_EVENT_LOWPOWER_ALARM, &alarm_type, sizeof(uint8_t));
+    
+    return ERRCODE_SUCC;
+}
+
 static const at_cmd_table_t g_custom_utils_cmd[] = {
     { (char *)"AT^CUSTOM_SN",      custom_utils_setsn, (char *)"123456789ABCDEF2345678" },
     { (char *)"AT^CUSTOM_SN_REQ",  custom_utils_getsn, (char *)" " },
@@ -1963,6 +2003,7 @@ static const at_cmd_table_t g_custom_utils_cmd[] = {
     { (char *)"AT^FACTORY",      custom_enter_factory_test_mode, (char *)" " },
     { (char *)"AT^SETUART",      custom_set_uart_status, (char *)" " },
     { (char *)"AT^GETBTMAC",      custom_get_btmac, (char *)" " },
+    { (char *)"AT^LOWPOWER",      custom_lowpower_alarm_test, (char *)" " },
 };