From 10dbf870d3d3c13093f23f3c38eeb7dad05df4e9 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Mon, 8 Jun 2026 11:23:35 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8D=E4=BD=8E=E7=94=B5=E9=87=8F?= =?utf8?q?=E7=AE=A1=E4=B8=8D=E4=BA=86=E6=9C=BA=EF=BC=8C=E5=8D=A1=E4=BD=8F?= =?utf8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../msg_center/src/msg_center_customer.cpp | 113 ++++++----- .../src/notify/charge_notification.cpp | 186 ++++++++++-------- .../battery/service/battery_service.cpp | 11 +- 3 files changed, 175 insertions(+), 135 deletions(-) diff --git a/code/sdk/application/wearable/n9/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/n9/service/msg_center/src/msg_center_customer.cpp index b3fdbe2c4..9b765ba39 100644 --- a/code/sdk/application/wearable/n9/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/n9/service/msg_center/src/msg_center_customer.cpp @@ -669,62 +669,79 @@ void MsgCenterNotifyChargeUnPlugProc(const Topic topic, Request* req) /*低电量提醒*/ void MsgCenterNotifyLowPowerAlarmProc(const Topic topic, Request* req) { -WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyProc:: LowPower Alarm !"); -uint8 *x= (uint8 *)(req->data); -const power_display_svr_api_t *display_api = power_display_svr_get_api(); -// if(*x==3) -// { -// if (display_api->get_screen_state() != SCREEN_ON) -// { -// display_api->turn_on_screen(); -// } -// display_api->set_screen_set_keepon_timeout(1000*5); -// //倒计时结束后,直接执行关机动画 -// low_power_play(); -// } -if(*x==0) -{ - //提醒低电充电 - if (display_api->get_screen_state() != SCREEN_ON) - { - display_api->turn_on_screen(); + if (req == NULL || req->data == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "低电量提醒: 请求数据为空"); + return; } - display_api->set_screen_set_keepon_timeout(1000*5); - set_lowpower_falg(0); - if (CheckPriority(topic)) + uint8 *x = (uint8 *)(req->data); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量提醒: 收到事件 topic=%u, alarm_type=%u", topic, *x); + + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (display_api == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "低电量提醒: 获取display_api失败"); + return; + } + + if (*x == 0) { - NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); - NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量提醒: 提醒低电充电"); + if (display_api->get_screen_state() != SCREEN_ON) + { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量提醒: 屏幕未亮, 先亮屏"); + display_api->turn_on_screen(); + } + display_api->set_screen_set_keepon_timeout(1000 * 5); + + set_lowpower_falg(0); + if (CheckPriority(topic)) + { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量提醒: 优先级检查通过, 显示充电提醒弹窗"); + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); + NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true); + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "低电量提醒: 优先级检查未通过, 不显示充电提醒弹窗"); + } } -} -else -{ - //电量过低,直接提醒关机 - if (display_api->get_screen_state() != SCREEN_ON) - { - display_api->turn_on_screen(); + else if (*x == 3) + { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量提醒: 倒计时结束, 执行关机动画 alarm_type=%u", *x); + if (display_api->get_screen_state() != SCREEN_ON) + { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量提醒: 屏幕未亮, 先亮屏"); + display_api->turn_on_screen(); + } + /* 倒计时弹窗 UI 已存在,直接播放关机动画,勿 StopNotify/ShowNotify 否则会重置倒计时 */ + OHOS::low_power_play(); } - display_api->set_screen_set_keepon_timeout(1000*10); - set_lowpower_falg(1); - if (NotificationManager::GetInstance()->HasNotifyShowing()) - NotificationManager::GetInstance()->StopNotify(); - if (CheckPriority(topic)) + else { - NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_ONE); - NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量提醒: 电量过低, 提醒关机 alarm_type=%u", *x); + if (display_api->get_screen_state() != SCREEN_ON) + { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量提醒: 屏幕未亮, 先亮屏"); + display_api->turn_on_screen(); + } + display_api->set_screen_set_keepon_timeout(1000 * 10); + set_lowpower_falg(1); + if (NotificationManager::GetInstance()->HasNotifyShowing()) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量提醒: 关闭当前弹窗"); + NotificationManager::GetInstance()->StopNotify(); + } + if (CheckPriority(topic)) + { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量提醒: 优先级检查通过, 显示关机提醒弹窗"); + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_ONE); + NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true); + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "低电量提醒: 优先级检查未通过, 不显示关机提醒弹窗"); + } } } -} - //TODO: 亮屏弹窗倒计时5秒关机(不需要取消,强制关机) - // DialModelCharge::GetInstance()->UpdatechargeStatus(0); - // SaveEleModel::GetInstance()->SetChargeStatus(0); - - // testCHANINGView *t=testCHANINGView::GetInstance(); - // if(t!=NULL) - // { - // t->ChangeViewcolor(false); - // } #ifdef SUPPORT_CAT1_MODEM void MsgCenterNotifyHfpIncomingProc(const Topic topic, Request* req) diff --git a/code/sdk/application/wearable/n9/service/msg_center/src/notify/charge_notification.cpp b/code/sdk/application/wearable/n9/service/msg_center/src/notify/charge_notification.cpp index e7ca83a0f..64a41836c 100644 --- a/code/sdk/application/wearable/n9/service/msg_center/src/notify/charge_notification.cpp +++ b/code/sdk/application/wearable/n9/service/msg_center/src/notify/charge_notification.cpp @@ -218,10 +218,8 @@ namespace OHOS { batteryprogress = new UICircleProgress(); } - batteryprogress->SetPosition( - 123, 123); // widget's left position and top position - batteryprogress->Resize(224, 222); // widget's width and height - batteryprogress->SetViewId("circleProgress1"); // Set style + batteryprogress->SetPosition(123, 123,224,222); + batteryprogress->SetViewId("circleProgress1"); batteryprogress->SetStyle(STYLE_BACKGROUND_OPA, 0x00); // Set additional property @@ -247,9 +245,9 @@ namespace OHOS { image_lightning = new UIImageView(); } - image_lightning->SetPosition(207, 176); // widget's left position and top position - image_lightning->Resize(70, 60); // widget's width and height - image_lightning->SetViewId("image2"); // Set style + image_lightning->SetPosition(207, 176); + image_lightning->Resize(70, 60); + image_lightning->SetViewId("image2"); image_lightning->SetStyle(STYLE_BORDER_COLOR, 0xff191919); char *image2imagesPath = "/user/res/solar-energy_1.bin"; image_lightning->SetSrc(image2imagesPath); @@ -259,9 +257,9 @@ namespace OHOS { image_circle = new UIImageView(); } - image_circle->SetPosition(126, 125); // widget's left position and top position - image_circle->Resize(194, 194); // widget's width and height - image_circle->SetViewId("image1"); // Set style + image_circle->SetPosition(126, 125); + image_circle->Resize(194, 194); + image_circle->SetViewId("image1"); char *image1imagesPath = "/user/res/Ellipse_37.bin"; image_circle->SetSrc(image1imagesPath); image_circle->SetVisible(true); @@ -270,9 +268,9 @@ namespace OHOS { UILabel_power = new UILabelExt(); } - UILabel_power->SetPosition(133, 252); // widget's left position and top position - UILabel_power->Resize(200, 60); // widget's width and height - UILabel_power->SetViewId("label5"); // Set style + UILabel_power->SetPosition(133, 252); + UILabel_power->Resize(200, 60); + UILabel_power->SetViewId("label5"); UILabel_power->SetStyle(STYLE_TEXT_FONT, 40); UILabel_power->SetText(buf); @@ -286,9 +284,9 @@ namespace OHOS { UILabel_Chargeing = new UILabelExt(); } - UILabel_Chargeing->SetPosition(133, 356); // widget's left position and top position - UILabel_Chargeing->Resize(200, 60); // widget's width and height - UILabel_Chargeing->SetViewId("label4"); // Set style + UILabel_Chargeing->SetPosition(133, 356); + UILabel_Chargeing->Resize(200, 60); + UILabel_Chargeing->SetViewId("label4"); UILabel_Chargeing->SetStyle(STYLE_TEXT_FONT, 30); // UILabel_Chargeing->SetText("正在充电"); // UILabel_Chargeing->SetTextId(STR_CHARGE); @@ -303,9 +301,9 @@ namespace OHOS { UILabel_time = new UILabelExt(); } - UILabel_time->SetPosition(173, 65); // widget's left position and top position - UILabel_time->Resize(120, 48); // widget's width and height - UILabel_time->SetViewId("label3"); // Set style + UILabel_time->SetPosition(173, 65); + UILabel_time->Resize(120, 48); + UILabel_time->SetViewId("label3"); UILabel_time->SetStyle(STYLE_TEXT_FONT, 40); // Set additional property UILabel_time->SetText(time_buf); @@ -401,8 +399,15 @@ namespace OHOS } osTimerId_t low_power_timer = NULL; + static uint8_t timer_falg_low_power = 6; void FreelowPower(void) { + if (low_power_timer != NULL) { + osTimerStop(low_power_timer); + osTimerDelete(low_power_timer); + low_power_timer = NULL; + } + timer_falg_low_power = 6; if (UIViewGroup_lowpower != nullptr) { UIViewGroup_lowpower->RemoveAll(); @@ -441,34 +446,46 @@ namespace OHOS UIViewGroup_lowpower = nullptr; } } - static uint8_t timer_falg_low_power = 6; + void low_power_TimerCallBack(int data) { - // uapi_poweroff_device(); // 关机 - if (timer_falg_low_power) + if (timer_falg_low_power == 0) { + return; + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "关机倒计时:%d", timer_falg_low_power); + timer_falg_low_power--; + UpdateLabel(alarm_UILabel, timer_falg_low_power, STR_LOW_POWER_NOTIF_2); + alarm_UILabel->Invalidate(); + if (timer_falg_low_power == 0) { - timer_falg_low_power--; - // char buf[34]={0}; - // sprintf(buf,"电量过低%ds后将自动关机",timer_falg_low_power); - // alarm_UILabel->GetText(); - // printf("%s\r\n",alarm_UILabel); - UpdateLabel(alarm_UILabel, timer_falg_low_power, STR_LOW_POWER_NOTIF_2); - alarm_UILabel->Invalidate(); - if (timer_falg_low_power == 0) - { - alarm_UILabel->SetVisible(false); + alarm_UILabel->SetVisible(false); + if (low_power_timer != NULL) { + osTimerStop(low_power_timer); + osTimerDelete(low_power_timer); + low_power_timer = NULL; + } + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "关机倒计时: 结束, 触发关机动画"); #ifdef SUPPORT_BATTERY_SERVICE - low_power_play_toUI(3); + low_power_play_toUI(3); #endif - } } + UNUSED(data); } void low_power_play() { - // uapi_poweroff_device(); // 关机 - - // osTimerStop(low_power_timer); + if (group == nullptr || ShutDownImageAnimatorView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "low_power_play: group or animator is null"); + return; + } + if (low_power_timer != NULL) { + osTimerStop(low_power_timer); + osTimerDelete(low_power_timer); + low_power_timer = NULL; + } + if (alarm_labelbutton != nullptr) { + alarm_labelbutton->SetVisible(false); + } group->SetVisible(true); UIImageAnimatorView::AnimatorStopListener *stoplistener = static_cast(lowppowrAnimatorStopListener::GetInstance()); ShutDownImageAnimatorView->SetAnimatorStopListener(stoplistener); @@ -478,53 +495,57 @@ namespace OHOS return; } ShutDownImageAnimatorView->Start(); + ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); #ifdef SUPPORT_BATTERY_SERVICE set_lowpower_show(1, 0); #endif } + // 低电量提醒 UIViewGroup *lowPowerShow() { - if (UIViewGroup_lowpower == nullptr) { UIViewGroup_lowpower = new UIViewGroup(); + if (UIViewGroup_lowpower == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "lowPowerShow: UIViewGroup_lowpower is null"); + return nullptr; + } UIViewGroup_lowpower->SetPosition(0, 0, 466, 466); - // UIViewGroup_lowpower->SetStyle(STYLE_BACKGROUND_OPA, 0); } - // Add ImageView to App if (alarm_img == nullptr) { alarm_img = new UIImageView(); + if (alarm_img == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "lowPowerShow: alarm_img is null"); + return nullptr; + } } - alarm_img->SetPosition(171, 155); // widget's left position and top position - alarm_img->Resize(100, 100); // widget's width and height - alarm_img->SetViewId("image1"); // Set style - - // Set additional property + alarm_img->SetPosition(171, 155); + alarm_img->Resize(100, 100); const char *imageimagesPath = "/user/res/lowpower.bin"; alarm_img->SetSrc(imageimagesPath); - - // Add to rootView - UIViewGroup_lowpower->Add(alarm_img); alarm_img->SetVisible(true); - - // Add Label to App + UIViewGroup_lowpower->Add(alarm_img); + /* -------------------------------------------------------------------------- */ if (alarm_UILabel == nullptr) { alarm_UILabel = new UILabelExt(); + if (alarm_UILabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "lowPowerShow: alarm_UILabel is null"); + return nullptr; + } } - alarm_UILabel->SetPosition(101, 215); // widget's left position and top position - alarm_UILabel->Resize(466, 212); // widget's width and height - alarm_UILabel->SetViewId("label1"); // Set style + alarm_UILabel->SetPosition(101, 215); + alarm_UILabel->Resize(466, 212); alarm_UILabel->SetStyle(STYLE_TEXT_FONT, 30); - - // Set additional property - if (battery_falg == 0) + if (battery_falg == 0) //低电量提醒 { - alarm_UILabel->SetPosition(110, 252); // widget's left position and top position - alarm_UILabel->Resize(245, 70); // widget's width and height - + alarm_UILabel->SetPosition(110, 252); + alarm_UILabel->Resize(245, 70); // alarm_UILabel->SetText("当前电量低于10%请及时充电"); alarm_UILabel->SetTextId(STR_LOW_POWER_NOTIF_1); @@ -536,11 +557,10 @@ namespace OHOS set_lowpower_show(0, 0); #endif } - // Set additional property - if (battery_falg == 1) + if (battery_falg == 1) //低电量关机 { alarm_UILabel->SetPosition(110, 252); - alarm_UILabel->Resize(245, 70); // widget's width and height + alarm_UILabel->Resize(245, 70); // alarm_UILabel->SetText("当前电量低于5%,将自动关机"); alarm_UILabel->SetTextId(STR_LOW_POWER_NOTIF_2); UpdateLabel(alarm_UILabel, 5, STR_LOW_POWER_NOTIF_2); @@ -548,6 +568,11 @@ namespace OHOS alarm_UILabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); alarm_UILabel->SetRollSpeed(0); alarm_UILabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + if (low_power_timer != NULL) { + osTimerStop(low_power_timer); + osTimerDelete(low_power_timer); + low_power_timer = NULL; + } osStatus_t retTimer; low_power_timer = osTimerNew((osTimerFunc_t)low_power_TimerCallBack, osTimerPeriodic, NULL, NULL); retTimer = osTimerStart(low_power_timer, 1000 * 1); @@ -560,32 +585,28 @@ namespace OHOS } timer_falg_low_power = 5; } - - // Add to rootView UIViewGroup_lowpower->Add(alarm_UILabel); alarm_UILabel->SetVisible(true); - - // Add LabelButtonExt to App + /* -------------------------------------------------------------------------- */ if (alarm_labelbutton == nullptr) { alarm_labelbutton = new UILabelButtonExt(); + if (alarm_labelbutton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "lowPowerShow: alarm_labelbutton is null"); + return nullptr; + } } - // alarm_labelbutton->SetPosition(165, 378); // widget's left position and top position - // alarm_labelbutton->Resize(135, 88); // widget's width and height - alarm_labelbutton->SetViewId(LOW_POWER_BUTTON); // Set style + alarm_labelbutton->SetViewId(LOW_POWER_BUTTON); alarm_labelbutton->SetPosition(0, 366, 466, 100); const char *ImgSrc = "/user/res/466x100button.bin"; alarm_labelbutton->SetImageSrc(ImgSrc, ImgSrc); - // Set additional property // alarm_labelbutton->SetText("确认"); alarm_labelbutton->SetTextId(STR_KONW); alarm_labelbutton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); alarm_labelbutton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - UIView::OnClickListener *button1Click = static_cast(lowppowrViewEventListener::GetInstance()); alarm_labelbutton->SetOnClickListener(button1Click); - - // Add to rootView UIViewGroup_lowpower->Add(alarm_labelbutton); alarm_labelbutton->SetVisible(true); UIViewGroup_lowpower->SetTouchable(true); @@ -600,19 +621,16 @@ namespace OHOS ShutDownImageAnimatorView->Start(); ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 关机动画已经开始了不能息屏 } - NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreelowPower); return UIViewGroup_lowpower; } lowppowrViewEventListener::lowppowrViewEventListener() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "lowppowrViewEventListener :%p", this); } lowppowrViewEventListener::~lowppowrViewEventListener() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~lowppowrViewEventListener"); } lowppowrViewEventListener *lowppowrViewEventListener::GetInstance(void) @@ -628,7 +646,12 @@ namespace OHOS { if (battery_falg) { - osTimerStop(low_power_timer); + if(low_power_timer != NULL) + { + osTimerStop(low_power_timer); + osTimerDelete(low_power_timer); + low_power_timer = NULL; + } low_power_play(); } else @@ -641,7 +664,6 @@ namespace OHOS NotificationManager::GetInstance()->StopNotify(); } return true; - UNUSED(event); } void lowppowrAnimatorStopListener::OnAnimatorStop(UIView &view) @@ -655,14 +677,6 @@ namespace OHOS shutdown_reboot_prejobs(REBOOT_TYPE); else shutdown_reboot_prejobs(SHUTDOWN_TYPE); - // uapi_poweroff_device(); // 关机 - - // NotificationManager::GetInstance()->StopNotify(); - // - // if(strcmp(view.GetViewId(),LOW_POWER_BUTTON)!=0) - // { - - // } } diff --git a/code/sdk/zhihui/services/battery/service/battery_service.cpp b/code/sdk/zhihui/services/battery/service/battery_service.cpp index 05561f491..c64db565d 100644 --- a/code/sdk/zhihui/services/battery/service/battery_service.cpp +++ b/code/sdk/zhihui/services/battery/service/battery_service.cpp @@ -654,20 +654,29 @@ void set_lowpower_show( uint8_t type,uint8_t data) errcode_t Play_shutdown_animation_notify(uint8_t alarm_level) { - //PRINT("alarm_level[%d],low_power_flag_1[%d],low_power_flag_2[%d]\n",alarm_level,low_power_flag_1,low_power_flag_2); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量UI: Play_shutdown_animation_notify alarm_level=%u, flag1=%u, flag2=%u", + alarm_level, low_power_flag_1, low_power_flag_2); + if(alarm_level==0 && low_power_flag_1) { //low_power_flag_1=0; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量UI: 发布充电提醒事件 alarm_level=0"); ChargerEventPublish(TOPIC_EVENT_LOWPOWER_ALARM,alarm_level); } else if(alarm_level==1 && low_power_flag_2) { //low_power_flag_2=0; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量UI: 发布关机倒计时提醒事件 alarm_level=1"); ChargerEventPublish(TOPIC_EVENT_LOWPOWER_ALARM,alarm_level); } else if(alarm_level!=0 && alarm_level!=1) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量UI: 发布关机动画事件 alarm_level=%u", alarm_level); ChargerEventPublish(TOPIC_EVENT_LOWPOWER_ALARM,alarm_level); } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "低电量UI: 未发布事件, alarm_level=%u 已被去重或条件不满足", alarm_level); + } return 0; } -- 2.17.1