密码锁:增加屏幕管理相关状态日志打印
authorCaisking <3449750381@qq.com>
Thu, 12 Sep 2024 12:06:57 +0000 (20:06 +0800)
committerCaisking <3449750381@qq.com>
Thu, 12 Sep 2024 12:06:57 +0000 (20:06 +0800)
code/sdk/application/wearable/fd230app/nativeui/screennotify/src/ui_screennotify.cpp

index 89f5464..e100581 100644 (file)
-#include <list>
-#include <cstdio>
-#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 <list>  
+#include <cstdio>  
+#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);
+#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 = 2; // 超时时间 秒
-    // 需要屏蔽掉的slice,ignore_slice_ids数组中的slice灭屏超时后不会调转到默认界面
-    uint16_t ignore_slice_ids[] = {
-        VIEW_INVALID,
-        VIEW_SAVEBAT,      // 省电模式
-        VIEW_TRAININGCRAD, // 训练卡片
-    };
-    static std::list<ScreenStatusNotifyCallback> g_callback;
-    static void ChangeToHomeView(void)
-    {
-        screen_context_t *sc = power_display_get_screen_context();
-        uint16_t current_slice_id = OHOS::NativeAbility::GetInstance().GetCurSliceId();
+#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<ScreenStatusNotifyCallback> 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)
-            {
-                return;
-            }
-        }
-        if (sc->screen_off_time_interval > g_back_to_home_interval)
-        {
-            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "screen off time = %u",
-                          sc->screen_off_time_interval);
-            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetNativeAbilityState = %u",
-                          OHOS::NativeAbility::GetInstance().GetNativeAbilityState());
-                               /*密码锁开关被打开*/
-        if (OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD_SWITCH))
-        {
-            if (OHOS::NativeAbility::GetInstance().GetNativeAbilityState() == STATE_ACTIVE)
-            {
+        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在忽略列表中,返回  
+            }  
+        }  
 
-#if 0
-                if (current_slice_id != VIEW_MAIN)
-                {
-                    /*进行主界面截断 不能滑动*/
-                    OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
-                }
-                else
-                {
-                    if (!OHOS::MainViewSample::GetInstance()->IsMainClockPage())
-                    {
-                        // 当前页面为主表盘的其他页面时,切换回主表盘页面
-                        OHOS::MainViewSample::GetInstance()->SwitchToClockPage();
-                    }
-                }
-#endif
-                    /*如果是未上锁界面或者是密码锁界面*/
-                    if (uapi_dev_runtime_get_lock_status() == 0)
-                    {
-                        /*重新进入一次主界面*/
-                        OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
-                        /*上锁*/
-                        uapi_dev_runtime_set_lock_status(1);
-                        /*设置表盘状态*/
-                        OHOS::MainModel::GetInstance().setDialState(OHOS::DialState::LOCK, true);
-                    }
-                    if (uapi_dev_runtime_get_lock_status() == 1 && (current_slice_id == VIEW_CODED_LOCK))
-                    {
-                        /*重新进入一次主界面*/
-                        OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
-                    }
-                }
-            }
-        }
-    }
+        // 打印屏幕关机时间  
+        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);  
 
-    void notify_screen_on_event(void)
-    {
-        for (auto callback : g_callback)
-        {
-            callback(SCREEN_STATUS_ON);
-        }
-        ChangeToHomeView();
-    }
+            // 打印锁定状态判断  
+            if (lockstate == 1)  
+            {  
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Lock state is enabled (lockstate == 1).");  
 
-    void notify_screen_off_event(void)
-    {
-        for (auto callback : g_callback)
-        {
-            callback(SCREEN_STATUS_OFF);
-        }
-    }
+                if (OHOS::NativeAbility::GetInstance().GetNativeAbilityState() == STATE_ACTIVE)  
+                {  
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Native ability state is active.");  
 
-    void set_back_to_home_interval(uint32_t time_sec)
-    {
-        g_back_to_home_interval = time_sec;
-    }
+                    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.");  
+        }  
+    }  
 
-    uint32_t get_back_to_home_interval(void)
-    {
-        return g_back_to_home_interval;
-    }
+    void notify_screen_on_event(void)  
+    {  
+        for (auto callback : g_callback)  
+        {  
+            callback(SCREEN_STATUS_ON);  
+        }  
+        ChangeToHomeView();  
+    }  
 
-    void registerNotifyScreenStatus(ScreenStatusNotifyCallback callback)
-    {
-        if (callback != nullptr)
-        {
-            g_callback.push_back(callback);
-        }
-    }
+    void notify_screen_off_event(void)  
+    {  
+        for (auto callback : g_callback)  
+        {  
+            callback(SCREEN_STATUS_OFF);  
+        }  
+    }  
 
-    void deregisterNotifyScreenStatus(ScreenStatusNotifyCallback callback)
-    {
-        if (callback != nullptr)
-        {
-            g_callback.remove(callback);
-        }
-    }
+    void set_back_to_home_interval(uint32_t time_sec)  
+    {  
+        g_back_to_home_interval = time_sec;  
+    }  
 
-#ifdef __cplusplus
-}
-#endif
+    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  
+}  
+#endif
\ No newline at end of file