#include "TjdUiAppLowPowerPresenter.h" #include "NativeAbility.h" #include "TjdUiAppLowPowerModel.h" #include "TjdUiAppLowPowerView.h" #include "TjdUiMsgCenter.h" #include "graphic_service.h" #include "hal_tick.h" #include "notification_manager.h" #include "power_display_service.h" #include "sys_config.h" #include "display_action.h" #include "rtc_api.h" #include "sql_setting.h" #include "sys_restart.h" #include "common_pm.h" extern "C" { #include "pm.h" } namespace TJD { #define ENABLE_PRINT_INFO 1 #if ENABLE_PRINT_INFO #define static_print_info(...) sys_ui_log_i(__VA_ARGS__) // 一般信息打印宏控制 #define static_print_warn(...) sys_ui_log_w(__VA_ARGS__) // 警告信息打印一般常开 #define static_print_error(...) sys_ui_log_e(__VA_ARGS__) // 错误信息打印一般常开 #define static_print_debug(...) sys_ui_log_d(__VA_ARGS__) // 调试信息打印一般常开 #else #define static_print_info(...) #define static_print_warn(...) #define static_print_error(...) #define static_print_debug(...) #endif static TjdUiAppLowPowerView *g_appLowPowerView = nullptr; static uint8_t g_battery = 20; static void DeleteLowPowerView() { OHOS::NotificationManager::GetInstance()->SetNotifyPriority(TJD_UI_PRIO_LOWEST); if (g_appLowPowerView != nullptr) { delete g_appLowPowerView; g_appLowPowerView = nullptr; } RunPopOutPageCallback(); } static OHOS::UIViewGroup *ShowLowPowerView() { /* 注册析构函数 */ OHOS::NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(DeleteLowPowerView); if (g_appLowPowerView == nullptr) { g_appLowPowerView = new TjdUiAppLowPowerView(g_battery, new TjdUiAppLowPowerPresenter()); } TjdUiAppLowPowerModel::GetInstance().MsgShakeEvent(); return g_appLowPowerView; } void TjdUiLowPowerMsgCenterMessageProc(const Topic topic, Request *req) { uint16_t sliceId = OHOS::NativeAbility::GetInstance().GetCurSliceId(); if (sliceId == TJD_APP_BATTERY_SAVER) { return; } const power_display_svr_api_t *display_api = power_display_svr_get_api(); display_api->turn_on_screen(); g_battery = *(uint8_t *)req->data; OHOS::NotificationManager::GetInstance()->SetNotifyPriority(TjdUiMsgCenterGetPriority(topic)); OHOS::NotificationManager::GetInstance()->ShowNotify(ShowLowPowerView, static_cast(topic), true); if(g_battery == 0){ static_print_info("shutdown system after low battery display\n"); // osDelay(2000); // tjd_action_display_lcd_off(); // osDelay(500); // /* 关机前的资源保存 */ // tjd_driver_rtc_save_time(); // /* 保存资源 */ // sql_setting_set_save_flag(true); // tjd_sys_restart_data_save(); // tjd_driver_pm_shutdown_event(); // tjd_driver_pm_power_down_event(); // uapi_sys_shipmode(0); } } TjdUiAppLowPowerPresenter::TjdUiAppLowPowerPresenter() { TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::SYS_KEY_TYPE); } TjdUiAppLowPowerPresenter::~TjdUiAppLowPowerPresenter() { TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::SYS_KEY_TYPE); } void TjdUiAppLowPowerPresenter::EnterViewOnClick(OHOS::UIView &view, EnterViewButtonType type) { ViewExitEvent(); if (type == EnterViewButtonType::CANCEL) { } else if (type == EnterViewButtonType::OK) { OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_BATTERY_SAVER); } } bool TjdUiAppLowPowerPresenter::OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event) { if (!TjdUiCommonOnKeyListener::CheckIsExitEvent(event)) { return true; } ViewExitEvent(); return true; } void TjdUiAppLowPowerPresenter::ViewExitEvent(void) { OHOS::NotificationManager::GetInstance()->StopNotify(); } } // namespace TJD