添加按键拦截功能(目前只在function键双击添加),若intercept_slice_ids数组中有给定的VIEWID则不触发该事件
authorluozheng <1732036298@qq.com>
Sat, 24 Aug 2024 07:11:15 +0000 (15:11 +0800)
committerluozheng <1732036298@qq.com>
Sat, 24 Aug 2024 07:11:15 +0000 (15:11 +0800)
code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp

index d3a7c65..2f89e3b 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-07-18 14:55:27
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-08-22 20:02:18
+ * @LastEditTime: 2024-08-24 14:48:41
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp
  */
 
 extern "C" uint8_t uapi_dev_runtime_get_lock_status(void);
 namespace OHOS
 {
+    static uint16_t intercept_slice_ids[] = {
+        VIEW_INVALID,
+        VIEW_SAVEBAT,      // 省电模式界面
+        VIEW_BLOOD_CHECK,  // 血氧检测界面
+        VIEW_HEART_CHECK,  // 心率检测界面
+        VIEW_TRAININGCRAD, // 训练控制卡片
+        VIEW_TEST,         // 产测测试界面
+    };
+
     RebootAndShutdownModel::RebootAndShutdownModel() {}
 
     RebootAndShutdownModel::~RebootAndShutdownModel() {}
@@ -91,12 +100,6 @@ namespace OHOS
         GraphicService::GetInstance()->PostGraphicEvent(std::bind(PowerKeyLongPressCallBack));
     }
 
-    static void SOSKeyLongPress(void)
-    {
-        start_SOS_phone_dail();
-    }
-
-
     /*注册电源键的长按事件*/
     bool RebootAndShutdownModel::RegisterPowerKeyLongPressEvent(void)
     {
@@ -107,12 +110,6 @@ namespace OHOS
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Register PowerKey LongPress Event error, ret = %d", ret);
             return false;
         }
-        ret = uapi_button_register_event_cb(SOSKeyLongPress, BUTTON1_LONGPRESS_8S);
-        if (ret != ERRCODE_SUCC)
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Register PowerKey LongPress Event error, ret = %d", ret);
-            return false;
-        }
         return true;
     }
 
@@ -274,19 +271,24 @@ namespace OHOS
         }
     }
 
+    static void SOSKeyLongPress(void)
+    {
+        start_SOS_phone_dail();
+    }
+
     static void HandFuncKeyOnLongPress(void)
     {
-        GraphicService::GetInstance()->PostGraphicEvent(std::bind(FuncKeyOnLongPressCallBack));
+        GraphicService::GetInstance()->PostGraphicEvent(std::bind(SOSKeyLongPress));
     }
 
-    /*注册功能键的长按(2s)事件*/
+    /*注册功能键的长按(8s)事件*/
     bool RebootAndShutdownModel::RegisterFuncKeyLongPressEvent(void)
     {
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RebootAndShutdownModel::RegisterFuncKeyLongPressEvent");
-        int32_t ret = uapi_button_register_event_cb(HandFuncKeyOnLongPress, BUTTON1_LONGPRESS_2S);
+        int32_t ret = uapi_button_register_event_cb(SOSKeyLongPress, BUTTON1_LONGPRESS_8S);
         if (ret != ERRCODE_SUCC)
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Register FuncKey LongPress Event error, ret = %d", ret);
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Register PowerKey LongPress Event error, ret = %d", ret);
             return false;
         }
         return true;
@@ -381,6 +383,14 @@ namespace OHOS
             return;
         }
 
+        uint16_t current_slice_id = OHOS::NativeAbility::GetInstance().GetCurSliceId();
+        for (uint16_t i = 0; i < sizeof(intercept_slice_ids) / sizeof(intercept_slice_ids); i++)
+        {
+            if (intercept_slice_ids[i] == current_slice_id)
+            {
+                return;
+            }
+        }
         const power_display_svr_api_t *display_api = power_display_svr_get_api();
         if (!display_api)
         {
@@ -438,7 +448,7 @@ namespace OHOS
         RegisterPowerKeyDoubleClickEvent();
         RegisterPowerKeyLongPressEvent();
         RegisterFuncKeyPressEvent();
-        // RegisterFuncKeyLongPressEvent();
+        RegisterFuncKeyLongPressEvent();
         // RegisterFuncKeyClickEvent();
         RegisterFuncKeyDoubleClickEvent();
     }