RK3588 Android13自定义一个按键实现长按短按

news/2024/7/16 9:13:38

一、kernel修改

diff --git a/arch/arm64/boot/dts/rockchip/rk3588-nvr-demo.dtsi b/arch/arm64/boot/dts/rockchip/rk3588-nvr-demo.dtsi
index 5aae5c613825..4cc1223f9cbf 100755
--- a/arch/arm64/boot/dts/rockchip/rk3588-nvr-demo.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3588-nvr-demo.dtsi
+       
+       gpio-keys {
+               status = "okay";
+               compatible = "gpio-keys";
+               autorepeat;
+               userf1 {
+                               label = "GPIO user key";
+                               linux,code = <KEY_USERKEY>;
+                               gpios = <&gpio1 RK_PA3 GPIO_ACTIVE_LOW>;
+                               debounce-interval = <100>;
+               };
+               userf1_lp {
+                               label = "GPIO user key lp";
+                               linux,code = <KEY_USERKEY_LP>;
+                               gpios = <&gpio1 RK_PD0 GPIO_ACTIVE_LOW>;
+                               debounce-interval = <100>;
+               };
+       };};diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
old mode 100644
new mode 100755
index f2d4e4daa818..9e95f3465620
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -29,6 +29,8 @@#include <linux/spinlock.h>#include <dt-bindings/input/gpio-keys.h>+static unsigned long start_time = 0;
+struct gpio_button_data {const struct gpio_keys_button *button;struct input_dev *input;
@@ -359,7 +361,8 @@ static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata)struct input_dev *input = bdata->input;unsigned int type = button->type ?: EV_KEY;int state;
-
+       unsigned long press_time = 0;
+       state = gpiod_get_value_cansleep(bdata->gpiod);if (state < 0) {dev_err(input->dev.parent,
@@ -371,7 +374,27 @@ static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata)if (state)input_event(input, type, button->code, button->value);} else {
-               input_event(input, type, *bdata->code, state);
+               if (*bdata->code == 744) {
+                       if (state) {
+                               start_time = jiffies;
+                       } else {
+                               press_time = jiffies_to_msecs(jiffies - start_time);
+                               printk(KERN_INFO "Button pressed for %lu milliseconds\n", press_time);
+                               if (press_time >= 5000) {
+                                       printk("factoryreset \n");
+                                       input_event(input, type, 745, 1);
+                                       input_sync(input);
+                                       input_event(input, type, 745, state);
+                               } else {
+                                       input_event(input, type, 744, 1);
+                                       input_sync(input);
+                                       input_event(input, type, 744, state);
+                               }
+                       }
+               } else {
+                       input_event(input, type, *bdata->code, state);
+               }
+               printk("gpio_keys_gpio_report_event input_event *bdata->code=%d,state = %d\n",*bdata->code, state);}input_sync(input);}
@@ -405,6 +428,7 @@ static irqreturn_t gpio_keys_gpio_isr(int irq, void *dev_id)* handler to run.*/input_report_key(bdata->input, button->code, 1);
+                       printk("gpio_keys_gpio_isr input_report_key *bdata->code=%d\n",button->code);}}@@ -424,6 +448,7 @@ static void gpio_keys_irq_timer(struct timer_list *t)spin_lock_irqsave(&bdata->lock, flags);if (bdata->key_pressed) {input_event(input, EV_KEY, *bdata->code, 0);
+               printk("gpio_keys_irq_timer input_event *bdata->code=%d\n",*bdata->code);input_sync(input);bdata->key_pressed = false;}
@@ -445,10 +470,12 @@ static irqreturn_t gpio_keys_irq_isr(int irq, void *dev_id)pm_wakeup_event(bdata->input->dev.parent, 0);input_event(input, EV_KEY, *bdata->code, 1);
+               printk("gpio_keys_irq_isr input_event *bdata->code=%d\n",*bdata->code);input_sync(input);if (!bdata->release_delay) {input_event(input, EV_KEY, *bdata->code, 0);
+                       printk("gpio_keys_irq_isr !bdata->release_delay input_event *bdata->code=%d\n",*bdata->code);input_sync(input);goto out;}diff --git a/include/dt-bindings/input/rk-input.h b/include/dt-bindings/input/rk-input.h
index 00b412927890..06c66d7c6bd4 100644
--- a/include/dt-bindings/input/rk-input.h
+++ b/include/dt-bindings/input/rk-input.h
@@ -578,6 +578,9 @@#define KEY_BRIGHTNESS_MIN             0x250   /* Set Brightness to Minimum */#define KEY_BRIGHTNESS_MAX             0x251   /* Set Brightness to Maximum */+#define KEY_USERKEY     0x2e8
+#define KEY_USERKEY_LP  0x2e9
+#define BTN_TRIGGER_HAPPY              0x2c0#define BTN_TRIGGER_HAPPY1             0x2c0#define BTN_TRIGGER_HAPPY2             0x2c1
diff --git a/include/uapi/linux/input-event-codes.h b/include/uapi/linux/input-event-codes.h
index 7989d9483ea7..1064395e72c3 100644
--- a/include/uapi/linux/input-event-codes.h
+++ b/include/uapi/linux/input-event-codes.h
@@ -778,6 +778,8 @@#define BTN_TRIGGER_HAPPY38            0x2e5#define BTN_TRIGGER_HAPPY39            0x2e6#define BTN_TRIGGER_HAPPY40            0x2e7
+#define KEY_USERKEY     0x2e8
+#define KEY_USERKEY_LP  0x2e9

二、framework修改

diff --git a/core/api/current.txt b/core/api/current.txt
index 1d610ab7536b..15e5b6487d13 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -48634,6 +48634,8 @@ package android.view {field public static final int KEYCODE_TV_ZOOM_MODE = 255; // 0xfffield public static final int KEYCODE_U = 49; // 0x31field public static final int KEYCODE_UNKNOWN = 0; // 0x0
+    field public static final int KEYCODE_USERKEY = 305; // 0x131
+    field public static final int KEYCODE_USERKEY_LP = 306; // 0x132field public static final int KEYCODE_V = 50; // 0x32field public static final int KEYCODE_VIDEO_APP_1 = 289; // 0x121field public static final int KEYCODE_VIDEO_APP_2 = 290; // 0x122
diff --git a/core/java/android/view/KeyEvent.java b/core/java/android/view/KeyEvent.java
index c3a638c4c36a..e5a21e3f3e06 100644
--- a/core/java/android/view/KeyEvent.java
+++ b/core/java/android/view/KeyEvent.java
@@ -866,6 +866,8 @@ public class KeyEvent extends InputEvent implements Parcelable {public static final int KEYCODE_DEMO_APP_3 = 303;/** Key code constant: Demo Application key #4. */public static final int KEYCODE_DEMO_APP_4 = 304;
+    public static final int KEYCODE_USERKEY = 305;
+    public static final int KEYCODE_USERKEY_LP = 306;/*** Integer value of the last KEYCODE. Increases as new keycodes are added to KeyEvent.
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index d86aa1122d3a..fb3bccc7fd80 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -2004,7 +2004,9 @@<enum name="KEYCODE_DEMO_APP_1" value="301" /><enum name="KEYCODE_DEMO_APP_2" value="302" /><enum name="KEYCODE_DEMO_APP_3" value="303" />
-        <enum name="KEYCODE_DEMO_APP_4" value="304" />
+       <enum name="KEYCODE_DEMO_APP_4" value="304" />
+       <enum name="KEYCODE_USERKEY" value="305" />
+       <enum name="KEYCODE_USERKEY_LP" value="306" /></attr><!-- ***************************************************************** -->
diff --git a/data/keyboards/Generic.kl b/data/keyboards/Generic.kl
index c81473ddcfc6..0096266539a4 100644
--- a/data/keyboards/Generic.kl
+++ b/data/keyboards/Generic.kl
@@ -410,6 +410,8 @@ key 580   APP_SWITCHkey 582   VOICE_ASSIST# Linux KEY_ASSISTANTkey 583   ASSIST
+key 744   USERKEY
+key 745   USERKEY_LP# Keys defined by HID usageskey usage 0x0c0067 WINDOW
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
old mode 100644
new mode 100755
index 40643f638ac0..3f573a8a52de
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -182,6 +182,8 @@ import android.view.accessibility.AccessibilityManager;import android.view.animation.Animation;import android.view.animation.AnimationUtils;import android.view.autofill.AutofillManagerInternal;
+import android.os.UserManager;
+import android.os.RecoverySystem;import com.android.internal.R;import com.android.internal.accessibility.AccessibilityShortcutController;
@@ -3031,6 +3033,27 @@ public class PhoneWindowManager implements WindowManagerPolicy {case KeyEvent.KEYCODE_DEMO_APP_4:Slog.wtf(TAG, "KEYCODE_APP_X should be handled in interceptKeyBeforeQueueing");return key_consumed;
+                       case KeyEvent.KEYCODE_USERKEY:
+                 //do nothing
+                                PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
+                                pm.reboot(null);
+                                Slog.wtf(TAG, "KeyEvent.KEYCODE_USERKEY in interceptKeyBeforeQueueing");
+                               break;
+                       case KeyEvent.KEYCODE_USERKEY_LP:
+                           // 检查是否允许当前用户执行恢复出厂设置操作
+                               UserManager um = mContext.getSystemService(UserManager.class);
+                               if (um.hasUserRestriction(UserManager.DISALLOW_FACTORY_RESET)) {
+                                       throw new SecurityException("Factory reset is not allowed for this user.");
+                               }
+
+                               // 执行恢复出厂设置操作
+                               try {
+                                       RecoverySystem.rebootWipeUserData(mContext);
+                               } catch (IOException e) {
+                                       // 处理异常
+                               }
+                               Slog.wtf(TAG, "KeyEvent.KEYCODE_USERKEY_LP in interceptKeyBeforeQueueing");
+                               break;case KeyEvent.KEYCODE_BRIGHTNESS_UP:case KeyEvent.KEYCODE_BRIGHTNESS_DOWN:if (down) {diff --git a/include/android/keycodes.h b/include/android/keycodes.h
index 3357660f5c..52750f400e 100644
--- a/include/android/keycodes.h
+++ b/include/android/keycodes.h
@@ -809,7 +809,8 @@ enum {AKEYCODE_DEMO_APP_3 = 303,/** Demo Application key #4. */AKEYCODE_DEMO_APP_4 = 304,
-
+    AKEYCODE_USERKEY = 305,
+    AKEYCODE_USERKEY_LP = 306,// NOTE: If you add a new keycode here you must also add it to several other files.//       Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.};
diff --git a/libs/input/InputEventLabels.cpp b/libs/input/InputEventLabels.cpp
index 2d768ce573..9cd92a7bef 100644
--- a/libs/input/InputEventLabels.cpp
+++ b/libs/input/InputEventLabels.cpp
@@ -330,7 +330,9 @@ namespace android {DEFINE_KEYCODE(DEMO_APP_1), \DEFINE_KEYCODE(DEMO_APP_2), \DEFINE_KEYCODE(DEMO_APP_3), \
-    DEFINE_KEYCODE(DEMO_APP_4)
+    DEFINE_KEYCODE(DEMO_APP_4), \
+    DEFINE_KEYCODE(USERKEY), \
+    DEFINE_KEYCODE(USERKEY_LP)// NOTE: If you add a new axis here you must also add it to several other files.


https://www.xjx100.cn/news/3417933.html

相关文章

Mysql:通过一张表里的父子级,递归查询并且分组分级

一张表&#xff1a;gc_jzst_single_base WITH RECURSIVE t1 AS ( SELECT single_id, old_build_single_id, single_name, bulid_code , 1 AS LEVEL, single_id groupFlag FROM gc_jzst_single_base WHE…

jupyter notebook anaconda环境下查看|加载|更换内核

文章目录 1 问题复现2 查看内核位置3 调整python解释器位置 1 问题复现 在conda虚拟环境中使用pip安装相应package&#xff0c; 但是在jupyter notebook中加载该package时报错 [ERROR]ModuleNotFoundError: No module named shap 此时&#xff0c;除去包安装出现问题以外&am…

【MySQL】MySQL Connect -- 详解

一、Connector / C 使用 要使用 C 语言连接 MySQL&#xff0c;需要使用 MySQL 官网提供的库&#xff0c;可以去官网进行下载&#xff1a;MySQL :: MySQL Community Downloads 我们使用 C 接口库来进行连接&#xff0c;要正确使用&#xff0c;还需要做一些准备工作&#xff1a…

【MyBatisPlus】MyBatisPlus介绍与使用

【MyBatisPlus】MyBatisPlus介绍与使用 文章目录 【MyBatisPlus】MyBatisPlus介绍与使用1、什么MyBatisPlus2、MyBatisPlus的CRUD操作3、MyBatisPlus分页使用 1、什么MyBatisPlus MyBatisPlus&#xff08;简称MP&#xff09;是基于MyBatis框架基础上开发的增强型工具&#xff0…

Unity DOTS技术(五)Archetype,Chunk,NativeArray

文章目录 一.Chunk和Archetype什么是Chunk?什么是ArchType 二.Archetype创建1.创建实体2.创建并添加组件3.批量创建 三.多线程数组NativeArray 本次介绍的内容如下: 一.Chunk和Archetype 什么是Chunk? Chunk是一个空间,ECS系统会将相同类型的实体放在Chunk中.当一个Chunk…

RK3568笔记二十八:CRNN车牌识别部署

若该文为原创文章&#xff0c;转载请注明原文出处。 想在RK3568上实现车牌识别&#xff0c;想到的方法是使用LPRNet网络识别或CRNN识别&#xff0c;本篇记录使用CRNN识别车牌&#xff0c;也可以换成LPRNet模型&#xff0c;原理一样。 一、平台介绍 1、训练平台&#xff1a;A…

CV每日论文---2024.6.3

1、Video-MME: The First-Ever Comprehensive Evaluation Benchmark of Multi-modal LLMs in Video Analysis 中文标题&#xff1a;Video-MME&#xff1a;视频分析领域首个多模态法学硕士综合评估基准 简介&#xff1a;Video-MME 是一个全面评估多模态大语言模型&#xff08;M…

PostgreSQL 修改表结构卡住不动

目录 1 问题2 实现 1 问题 今天遇到的一个问题记录一下&#xff0c;因为系统上的一个改动需要同步脚本至测试库上&#xff0c;具体的脚本内容也很简单,就是修改了某张表的一个字段。但是无论怎么操作都是一直卡住&#xff0c;表的数据量很小就十几条数据所以初步怀疑是表被锁了…