From edc6b2b0fcf3bcc64cf5be9c050d770afdf01a32 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Sat, 12 Oct 2024 18:46:38 +0800 Subject: [PATCH] =?utf8?q?#799=E9=95=BF=E6=8C=89=E8=A1=A8=E7=9B=98?= =?utf8?q?=EF=BC=8C=E8=BF=9B=E5=85=A5=E8=A1=A8=E7=9B=98=E9=A2=84=E8=A7=88?= =?utf8?q?=E7=95=8C=E9=9D=A2=EF=BC=8C=E6=89=8B=E8=A1=A8=E6=81=AF=E5=B1=8F?= =?utf8?q?=E5=90=8E=E4=B8=8D=E7=AE=A1=E5=A4=9A=E4=B9=85=E4=BA=AE=E5=B1=8F?= =?utf8?q?=EF=BC=8C=E6=89=8B=E8=A1=A8=E8=BF=98=E6=98=AF=E8=A1=A8=E7=9B=98?= =?utf8?q?=E9=A2=84=E8=A7=88=E7=95=8C=E9=9D=A2=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../screennotify/include/ui_screennotify.h | 12 +- .../screennotify/src/ui_screennotify.cpp | 299 +++++++++--------- 2 files changed, 160 insertions(+), 151 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/screennotify/include/ui_screennotify.h b/code/sdk/application/wearable/fd230app/nativeui/screennotify/include/ui_screennotify.h index 4d202759a..6a6d6aa3d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/screennotify/include/ui_screennotify.h +++ b/code/sdk/application/wearable/fd230app/nativeui/screennotify/include/ui_screennotify.h @@ -1,9 +1,4 @@ -/** - * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. - * Description: Power display action header file. - * Author: - * Create: - */ + #ifndef OHOS_UI_SCREENNOTIFY_H #define OHOS_UI_SCREENNOTIFY_H #include "ohos_types.h" @@ -34,11 +29,14 @@ void set_back_to_home_interval(uint32_t time_sec); /** * @brief 获取灭屏后slice的存活期,需要在slice对应的Presentor的OnStart方法中调用 - * 默认存活期是5秒,灭屏超过5秒后再次亮屏会跳回主界面 + * 默认存活期是5秒,灭屏超过10秒后再次亮屏会跳回主界面 * @param time_sec 获取的slice灭屏后的存活期时间 */ uint32_t get_back_to_home_interval(void); +void handleLockEnabled(uint16_t current_slice_id); +void handleLockDisabled(uint16_t current_slice_id); + #ifdef __cplusplus } #endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/screennotify/src/ui_screennotify.cpp b/code/sdk/application/wearable/fd230app/nativeui/screennotify/src/ui_screennotify.cpp index e100581a8..c238397bc 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/screennotify/src/ui_screennotify.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/screennotify/src/ui_screennotify.cpp @@ -1,145 +1,156 @@ -#include -#include -#include "ability_state.h" -#include "cmsis_os2.h" -#include "common_def.h" -#include "Ability.h" -#include "wearable_log.h" -#include "graphic_service.h" -#include "power_display_service.h" -#include "NativeAbility.h" -#include "AppViewIDs.h" -#include "MainViewSample.h" -#include "ui_screennotify.h" -#include "components/root_view.h" -#include "ConfigModel.h" - -#include "ui_service.h" -extern "C" void uapi_dev_runtime_set_lock_status(uint8_t status); -extern "C" uint8_t uapi_dev_runtime_get_lock_status(void); - -#ifdef __cplusplus -extern "C" -{ -#endif - static uint32_t g_back_to_home_interval = 3; // 超时时间 秒 - uint16_t ignore_slice_ids[] = { - VIEW_INVALID, - VIEW_SAVEBAT, // 省电模式 - VIEW_TRAININGCRAD, // 训练卡片 - }; - static std::list g_callback; - - static void ChangeToHomeView(void) - { - screen_context_t *sc = power_display_get_screen_context(); - uint16_t current_slice_id = OHOS::NativeAbility::GetInstance().GetCurSliceId(); - - for (uint16_t i = 0; i < sizeof(ignore_slice_ids) / sizeof(uint16_t); i++) - { - if (ignore_slice_ids[i] == current_slice_id) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Current slice ID %u is ignored.", current_slice_id); - return; // 如果当前slice在忽略列表中,返回 - } - } - - // 打印屏幕关机时间 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Screen off time interval = %u", sc->screen_off_time_interval); - - if (sc->screen_off_time_interval > g_back_to_home_interval) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Screen off timeout exceeded g_back_to_home_interval."); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetNativeAbilityState = %u", OHOS::NativeAbility::GetInstance().GetNativeAbilityState()); - - int lockstate = OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD_SWITCH); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "lockstate = %d", lockstate); - - // 打印锁定状态判断 - if (lockstate == 1) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Lock state is enabled (lockstate == 1)."); - - if (OHOS::NativeAbility::GetInstance().GetNativeAbilityState() == STATE_ACTIVE) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Native ability state is active."); - - if (uapi_dev_runtime_get_lock_status() == 0) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Device is unlocked (lock status == 0)."); - OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); - uapi_dev_runtime_set_lock_status(1); // 上锁 - OHOS::MainModel::GetInstance().setDialState(OHOS::DialState::LOCK, true); - } - else if (uapi_dev_runtime_get_lock_status() == 1 && (current_slice_id == VIEW_CODED_LOCK)) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Device is locked (lock status == 1) and current slice is VIEW_CODED_LOCK."); - OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); - } - else - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Device is in an inactive lock state or current slice is not VIEW_CODED_LOCK."); - } - } - else - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Native ability state is not active."); - } - } - else - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Lock state is not enabled (lockstate != 1)."); - } - } - else - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Screen off time interval is within limits."); - } - } - - void notify_screen_on_event(void) - { - for (auto callback : g_callback) - { - callback(SCREEN_STATUS_ON); - } - ChangeToHomeView(); - } - - void notify_screen_off_event(void) - { - for (auto callback : g_callback) - { - callback(SCREEN_STATUS_OFF); - } - } - - void set_back_to_home_interval(uint32_t time_sec) - { - g_back_to_home_interval = time_sec; - } - - uint32_t get_back_to_home_interval(void) - { - return g_back_to_home_interval; - } - - void registerNotifyScreenStatus(ScreenStatusNotifyCallback callback) - { - if (callback != nullptr) - { - g_callback.push_back(callback); - } - } - - void deregisterNotifyScreenStatus(ScreenStatusNotifyCallback callback) - { - if (callback != nullptr) - { - g_callback.remove(callback); - } - } - -#ifdef __cplusplus -} +#include "ui_screennotify.h" +#include "Ability.h" +#include "AppViewIDs.h" +#include "ConfigModel.h" +#include "MainViewSample.h" +#include "NativeAbility.h" +#include "ability_state.h" +#include "cmsis_os2.h" +#include "common_def.h" +#include "components/root_view.h" +#include "graphic_service.h" +#include "power_display_service.h" +#include "wearable_log.h" +#include +#include + +extern "C" void uapi_dev_runtime_set_lock_status(uint8_t status); +extern "C" uint8_t uapi_dev_runtime_get_lock_status(void); + +#ifdef __cplusplus +extern "C" { +#endif + +static uint32_t g_back_to_home_interval = 3; // 超时时间 3秒 +static const uint32_t screen_off_time_interval = 10; // 超时时间 10秒 +//息屏不上锁 +const uint16_t ignore_slice_ids[] = { + VIEW_INVALID, + VIEW_SAVEBAT, // 省电模式 + VIEW_TRAININGCRAD, // 训练卡片 +}; +//息屏10秒回到主界面 +const uint16_t special_slice_ids[] = { + VIEW_ADD_CARD, //卡片管理 + VIEW_SET_DIAL, //表盘管理 + VIEW_HEART_CHART //心率检测 +}; + +static std::unordered_set g_callbacks; + +static bool isSliceIgnored(uint16_t slice_id) { + for (uint16_t id : ignore_slice_ids) { + if (id == slice_id) { + return true; + } + } + return false; +} + +static void ChangeToHomeView(void) { + screen_context_t *sc = power_display_get_screen_context(); + uint16_t current_slice_id = + OHOS::NativeAbility::GetInstance().GetCurSliceId(); + + if (isSliceIgnored(current_slice_id)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Current slice ID %u is ignored.", + current_slice_id); + return; + } + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Screen off time interval = %u", + sc->screen_off_time_interval); + + if (sc->screen_off_time_interval > g_back_to_home_interval) { + int lockstate = OHOS::ConfigModel::GetInstance()->get_configData_int( + OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD_SWITCH); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "lockstate = %d", lockstate); + + if (lockstate == 1) { + handleLockEnabled(current_slice_id); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "Lock state is not enabled (lockstate != 1)."); + } + } + if (sc->screen_off_time_interval > g_back_to_home_interval) { + handleLockDisabled(current_slice_id); + } +} + +void handleLockEnabled(uint16_t current_slice_id) { + if (OHOS::NativeAbility::GetInstance().GetNativeAbilityState() == + STATE_ACTIVE) { + if (uapi_dev_runtime_get_lock_status() == 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "Device is unlocked (lock status == 0)."); + OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); + uapi_dev_runtime_set_lock_status(1); // 上锁 + OHOS::MainModel::GetInstance().setDialState(OHOS::DialState::LOCK, true); + } else if (current_slice_id == VIEW_CODED_LOCK) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "Device is locked (lock status == 1) and current slice is " + "VIEW_CODED_LOCK."); + OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "Device is in an inactive lock state or current slice is " + "not VIEW_CODED_LOCK."); + } + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "Native ability state is not active."); + } +} + +void handleLockDisabled(uint16_t current_slice_id) { + int lockstate = OHOS::ConfigModel::GetInstance()->get_configData_int( + OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD_SWITCH); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "lockstate = %d", lockstate); + + if (lockstate == 0) { + for (uint16_t id : special_slice_ids) { + if (id == current_slice_id) { + OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); + return; + } + } + } +} + +void notify_screen_on_event(void) { + for (auto callback : g_callbacks) { + callback(SCREEN_STATUS_ON); + } + ChangeToHomeView(); +} + +void notify_screen_off_event(void) { + for (auto callback : g_callbacks) { + callback(SCREEN_STATUS_OFF); + } +} + +void set_back_to_home_interval(uint32_t time_sec) { + g_back_to_home_interval = time_sec; +} + +uint32_t get_back_to_home_interval(void) { return g_back_to_home_interval; } + +void registerNotifyScreenStatus(ScreenStatusNotifyCallback callback) { + if (callback != nullptr) { + g_callbacks.insert(callback); + } +} + +void deregisterNotifyScreenStatus(ScreenStatusNotifyCallback callback) { + if (callback != nullptr) { + g_callbacks.erase(callback); + } +} + +#ifdef __cplusplus +} #endif \ No newline at end of file -- 2.17.1