RK3229 Android9自定义一个按键实现长按短按

一、kernel修改

--- a/arch/arm/boot/dts/rk3229-evb-android.dtsi
+++ b/arch/arm/boot/dts/rk3229-evb-android.dtsi
@@ -18,26 +18,25 @@};gpio_keys {
+               status = "okay";compatible = "gpio-keys";#address-cells = <1>;#size-cells = <0>;autorepeat;pinctrl-names = "default";
-               pinctrl-0 = <&pwr_key>;
-               pinctrl-1 = <&vol_up_key>;
-
-               power_key: power-key {
-                       label = "GPIO Key Power";
-                       gpios = <&gpio3 23 GPIO_ACTIVE_LOW>;
-                       linux,code = <KEY_POWER>;
+               pinctrl-0 = <&rst_key>;
+               userf1 {
+                       label = "GPIO user key";
+                       linux,code = <KEY_USERKEY>;
+                       gpios = <&gpio0 RK_PA0 GPIO_ACTIVE_LOW>;debounce-interval = <100>;
-                       wakeup-source;};
-               volume_up: volume-up-key {
-                       label = "GPIO Key Volume up";
-                       gpios = <&gpio3 25 GPIO_ACTIVE_LOW>;
-                       linux,code = <KEY_VOLUMEUP>;
+               userf1_lp {
+                       label = "GPIO user key lp";
+                       linux,code = <KEY_USERKEY_LP>;
+                       gpios = <&gpio0 RK_PA1 GPIO_ACTIVE_LOW>;
+                       debounce-interval = <100>;};};@@ -295,7 +294,7 @@};&i2c0 {
-       status = "okay";
+       status = "disabled";hym8563: hym8563@51 {compatible = "haoyu,hym8563";
@@ -344,6 +343,9 @@vol_up_key: vol-up-key {rockchip,pins = <3 25 RK_FUNC_GPIO &pcfg_pull_up>;};
+               rst_key: rst-key {
+                       rockchip,pins = <0 0 RK_FUNC_GPIO &pcfg_pull_none>;
+               };};sdmmc {
diff --git a/arch/arm/boot/dts/rk3229-evb.dts b/arch/arm/boot/dts/rk3229-evb.dts
old mode 100644
new mode 100755
index fc4f19fb2563..27109f421c8a
--- a/arch/arm/boot/dts/rk3229-evb.dts
+++ b/arch/arm/boot/dts/rk3229-evb.dts
@@ -268,7 +268,7 @@};&i2c0 {
-       status = "okay";
+       status = "disabled";hym8563: hym8563@51 {compatible = "haoyu,hym8563";
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
old mode 100644
new mode 100755
index bef317ff7352..380deaf8277c
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -32,6 +32,10 @@#include <linux/of_irq.h>#include <linux/spinlock.h>+#include <linux/reboot.h>
+
+static unsigned long start_time = 0;
+struct gpio_button_data {const struct gpio_keys_button *button;struct input_dev *input;
@@ -341,6 +345,7 @@ static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata)const struct gpio_keys_button *button = bdata->button;struct input_dev *input = bdata->input;unsigned int type = button->type ?: EV_KEY;
+       unsigned long press_time = 0;int state = gpio_get_value_cansleep(button->gpio);if (state < 0) {
@@ -353,7 +358,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, button->code, !!state);
+               if (button->code == 744) {
+                       press_time = jiffies_to_msecs(jiffies - start_time);
+                       printk(KERN_INFO "Button pressed for %lu milliseconds,start_time=%lu,jiffies=%lu\n", press_time,start_time,jiffies);
+                       if (start_time && press_time >= 5000) {
+                               printk("factoryreset \n");
+                               input_event(input, type, 745, 1);
+                               input_sync(input);
+                               input_event(input, type, 745, state);
+                       } else if (!state && start_time && press_time >= 100) {
+                               input_event(input, type, 744, 1);
+                               input_sync(input);
+                               input_event(input, type, 744, state);
+                               printk("reboot \n");
+                               kernel_restart(NULL);  // ִ<D0>и<B4>λ<B2><D9><D7><F7>
+                       }
+                       start_time = jiffies;
+               } else {
+                       start_time = 0;
+                       input_event(input, type, button->code, state);
+               }
+               printk("gpio_keys_gpio_report_event input_event *bdata->code=%d,state = %d\n",button->code, state);}input_sync(input);}
diff --git a/include/dt-bindings/input/rk-input.h b/include/dt-bindings/input/rk-input.h
old mode 100644
new mode 100755
index 00b412927890..1bf6e0abb2bc
--- 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
old mode 100644
new mode 100755
index 9e07bf4259e1..ab66f6e2d3c7
--- a/include/uapi/linux/input-event-codes.h
+++ b/include/uapi/linux/input-event-codes.h
@@ -653,6 +653,9 @@#define BTN_TRIGGER_HAPPY39            0x2e6#define BTN_TRIGGER_HAPPY40            0x2e7+#define KEY_USERKEY                     0x2e8
+#define KEY_USERKEY_LP                  0x2e9
+/* We avoid low common keys in module aliases so they don't get huge. */#define KEY_MIN_INTERESTING    KEY_MUTE#define KEY_MAX                        0x2ff

二、framework修改

frameworks/base$ git diff
diff --git a/api/current.txt b/api/current.txt
old mode 100644
new mode 100755
index 38afeedc201..1094e2158df
--- a/api/current.txt
+++ b/api/current.txt
@@ -46649,6 +46649,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_VOICE_ASSIST = 231; // 0xe7field public static final int KEYCODE_VOLUME_DOWN = 25; // 0x19
diff --git a/core/java/android/view/KeyEvent.java b/core/java/android/view/KeyEvent.java
old mode 100644
new mode 100755
index f9d19dca872..bbf4ff81a9e
--- a/core/java/android/view/KeyEvent.java
+++ b/core/java/android/view/KeyEvent.java
@@ -819,6 +819,8 @@ public class KeyEvent extends InputEvent implements Parcelable {public static final int KEYCODE_TV_KEYMOUSE_DOWN = 289;/** Key code constant: Tv controlloer switch mouse key*/public static final int KEYCODE_TV_KEYMOUSE_MODE_SWITCH = 290;
+       public static final int KEYCODE_USERKEY = 305;
+       public static final int KEYCODE_USERKEY_LP = 306;private static final int LAST_KEYCODE = KEYCODE_TV_KEYMOUSE_MODE_SWITCH;// NOTE: If you add a new keycode here you must also add it to:
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
old mode 100644
new mode 100755
index f4ae5585661..4b8b302ac73
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -1909,6 +1909,8 @@<enum name="KEYCODE_TV_KEYMOUSE_UP" value="288" /><enum name="KEYCODE_TV_KEYMOUSE_DOWN" value="289" /><enum name="KEYCODE_TV_KEYMOUSE_MODE_SWITCH" value="290" />
+               <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
old mode 100644
new mode 100755
index 8699cb491df..a548bb01757
--- a/data/keyboards/Generic.kl
+++ b/data/keyboards/Generic.kl
@@ -409,6 +409,9 @@ key 523   POUNDkey 580   APP_SWITCHkey 582   VOICE_ASSIST+key 744   USERKEY
+key 745   USERKEY_LP
+# Keys defined by HID usageskey usage 0x0c006F BRIGHTNESS_UPkey usage 0x0c0070 BRIGHTNESS_DOWN
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 a33ca98aa59..ef02c1598cc
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -262,6 +262,8 @@ import android.view.animation.AnimationSet;import android.view.animation.AnimationUtils;import android.view.autofill.AutofillManagerInternal;import android.view.inputmethod.InputMethodManagerInternal;
+import android.os.UserManager;
+import android.os.RecoverySystem;import com.android.internal.R;import com.android.internal.accessibility.AccessibilityShortcutController;
@@ -3904,6 +3906,23 @@ public class PhoneWindowManager implements WindowManagerPolicy {} else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {Slog.wtf(TAG, "KEYCODE_VOICE_ASSIST should be handled in interceptKeyBeforeQueueing");return -1;
+        } else if (keyCode == KeyEvent.KEYCODE_USERKEY) {
+            //do nothing
+                       //PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
+                       //pm.reboot(null);
+                       Slog.wtf(TAG, "KeyEvent.KEYCODE_USERKEY in interceptKeyBeforeQueueing");
+                       return -1;
+        } else if (keyCode == 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");
+                       return -1;} else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {if (down && repeatCount == 0) {mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);wzh@lenkeng-HP-Pro-Tower-ZHAN-99-G9-Desktop-PC:/media/extern_sdb/wzh/rk3229_9.0/frameworks/native$ git diff
diff --git a/include/android/keycodes.h b/include/android/keycodes.h
old mode 100644
new mode 100755
index 1b5908631..6bf9c98a1
--- a/include/android/keycodes.h
+++ b/include/android/keycodes.h
@@ -776,7 +776,9 @@ enum {AKEYCODE_TV_KEYMOUSE_RIGHT = 287,AKEYCODE_TV_KEYMOUSE_UP = 288,AKEYCODE_TV_KEYMOUSE_DOWN = 289,
-    AKEYCODE_TV_KEYMOUSE_MODE_SWITCH = 290
+    AKEYCODE_TV_KEYMOUSE_MODE_SWITCH = 290,
+    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/include/input/InputEventLabels.h b/include/input/InputEventLabels.h
old mode 100644
new mode 100755
index 3fd33a7fe..7d1223907
--- a/include/input/InputEventLabels.h
+++ b/include/input/InputEventLabels.h
@@ -330,6 +330,8 @@ static const InputEventLabel KEYCODES[] = {DEFINE_KEYCODE(SYSTEM_NAVIGATION_RIGHT),DEFINE_KEYCODE(ALL_APPS),DEFINE_KEYCODE(REFRESH),
+    DEFINE_KEYCODE(USERKEY),
+    DEFINE_KEYCODE(USERKEY_LP),{ NULL, 0 }};

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/2877.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

Java 打印流:PrintStream 与 PrintWriter 详解

在 Java 编程中&#xff0c;System.out.println() 的使用频率恐怕不亚于 main 方法的使用频率。其中&#xff0c;System.out 返回的正是打印流 PrintStream。除此之外&#xff0c;Java 还提供了另一个打印流 PrintWriter&#xff0c;它们分别继承自 OutputStream 和 Writer&…

RESTful风格

目录 一、什么是RESTful 1.1 RESTFul对WEB服务接口的规定包括&#xff1a; 1.2 REST对请求方式的具体约束如下&#xff1a; 1.3 REST对URL的具体约束如下&#xff1a; 1.4 RESTFul的核心概念&#xff1a; 二、RESTful风格与传统方式对比 三、RESTful风格演示 3.1 查询所…

运维工具之docker入门

1.容器与docker 1.什么是容器&#xff1f; 容器是一种轻量级的&#xff0c;可移植的软件运行环境。它将软件程序本身及软件依赖库打包在一起。可以在不同平台和系统上运行。 2.什么是LXC LXC就是Linux container,。LXC是一种虚拟化技术&#xff0c;可以在操作系统层级上为应…

Ubuntu系统安装NVIDIA驱动、CUDA、PyTorch等GPU深度学习环境

学习目标&#xff1a; 在Ubuntu系统上安装CUDA、PyTorch等GPU深度学习环境&#xff0c;主要目标是为深入研究深度学习和深度强化学习提供高效的计算支持。通过构建GPU环境&#xff0c;计划掌握深度学习的基本概念和算法应用&#xff0c;提高模型训练效率&#xff0c;特别是在复…

地理信息科学专业想搞GIS开发:学前端还是后端?

地理信息科学专业的同学是学前端开发比较好呢还是学后端开发比较好呢&#xff1f; 部分网友&#xff1a;学前端更好 主修前端更好&#xff0c;因为地信学后端&#xff0c;是卷不赢学计算机的 本科卷前端&#xff0c;硕士阶段可以卷后端 甚至有网友直呼&#xff0c;地信根本没有…

软件测试学习笔记丨Flask框架-请求与响应

本文转自测试人社区&#xff0c;原文链接&#xff1a;https://ceshiren.com/t/topic/23408 请求方法 from flask import Flaskapp Flask(__name__)app.route("/cases", methods["get"]) def get_case():return {"code": 0, "msg": &…

你敢想象吗?我能远程控制家里的电脑进入Bios

老家的爸妈用电脑也不知怎的&#xff0c;偶尔就不行了。这个偶尔还挺频繁的&#xff0c;我自己又会修电脑&#xff0c;但奈何距离太远&#xff01;如果叫别人上门修电脑&#xff0c;一次就是200…… 我的心在滴血啊在滴血&#xff5e;如果有这么一款产品&#xff0c;就算电脑无…

基于STM32的温湿度监测器教学

引言 随着科技的发展&#xff0c;温湿度监测在农业、仓储、环境监测等领域的应用越来越广泛。本文将指导您如何基于STM32开发一个简单的温湿度监测器&#xff0c;使用常用的DHT11或DHT22传感器进行数据采集&#xff0c;并将监测结果显示在LCD或OLED屏幕上。 项目名称 STM32温湿…

科研绘图系列:R语言组合堆积图(stacked plot)

文章目录 介绍加载R包数据数据预处理画图1画图2组合图形系统信息介绍 堆积图(Stacked Chart),也称为堆叠图,是一种常用的数据可视化图表,主要用于展示不同类别的数据量在总体中的分布情况。堆积图可以是柱状图、条形图或面积图的形式,其中各个类别的数据量被叠加在一起,…

红黑树的平衡之舞:数据结构中的优雅艺术

文章目录 前言&#x1f680;一、红黑树的介绍1.1 红黑树的概念1.2 红黑树的特点1.3 红黑树的性质 &#x1f680;二、红黑树结点的定义&#x1f680;三、红黑树的框架&#x1f680;四、旋转操作&#x1f680;五、红黑树的插入操作5.1 uncle结点存在且为红5.2 uncle结点不存在或者…

ONLYOFFICE 8.2版本产品评测——遥遥领先,助力自动化办公

ONLYOFFICE 产品测试体验报告总结 知孤云出岫-CSDN博客 目录 产品介绍——篇【1】 一.关于 ONLYOFFICE 桌面编辑器 二.关于 ONLYOFFICE 协作空间 三.关于 ONLYOFFICE 文档 四.关于 ONLYOFFICE的版本介绍 产品新功能——篇【2】 一.关于 ONLYOFFICE的新增功能介绍 二.ONL…

【Linux驱动开发】通过设备树节点来配置和调用GPIO(pinctrl节点和gpio-controller)

【Linux驱动开发】通过设备树节点来配置和调用GPIO&#xff08;pinctrl节点和gpio-controller&#xff09; 文章目录 设备树下pinctrl节点GPIO控制节点调用方法GPIO输入附录&#xff1a;嵌入式Linux驱动开发基本步骤开发环境驱动文件编译驱动安装驱动自动创建设备节点文件 驱动…

【Linux】安装 SQL Server 命令行工具 mssql-tools18(Ubuntu 22.04)

引言 mssql-tools18 是一个包含 Microsoft SQL Server 命令行工具的软件包。这些工具包括 sqlcmd 和 bcp。 sqlcmd 是一个允许你用命令行与 SQL Server 进行交互的工具。你可以用它来运行 SQL 脚本&#xff0c;执行数据库维护任务&#xff0c;以及进行其他数据库管理操作。 b…

库存管理内训课件|39页PPT

文件是一份关于库存管理的内训课件&#xff0c;内容涵盖了库存管理的定义、分类、作用、存在的问题、管控目标以及具体管控措施。以下是对课件内容的总结&#xff1a; 1. 定义及分类 库存&#xff1a;为满足未来需求而暂时闲置的有价值的资源&#xff0c;与物品是否处于运动状…

大零售时代下融合发展的新路径:定制开发技术的应用与思考

摘要&#xff1a;本文探讨在大零售背景下&#xff0c;传统零售边界模糊&#xff0c;融合成为趋势。分析大零售包含的跨行业跨业态融合等三个层面&#xff0c;重点阐述定制开发技术中的 21 链动模式、AI 智能名片和 S2B2C 商城小程序在推动大零售发展中的作用和意义&#xff0c;…

OceanBase 安装使用详细说明

OceanBase 安装使用详细说明 一、系统环境要求二、安装OceanBase环境方案一:在线下载并安装all-in-one安装包方案二:离线安装all-in-one安装包安装前的准备工作三、配置OceanBase集群编辑配置文件部署和启动集群连接到集群集群状态和管理四、创建业务租户和数据库创建用户并赋…

基于LabVIEW应用ARINC 429板卡实现数据通讯——(下篇)

五、基于LabVIEW实现数据通讯 基于LabVIEW实现429板卡的数据通讯是调用API 动态链接库文件来实现的。该文件中有许多的板卡操作函数&#xff0c;在调用板卡中必须按照一定的函数调用流程来操作板卡&#xff0c;否则极易出现板卡操作错误。 1、API函数的调用步骤 API函数的调…

Android Studio打包时不显示“Generate Signed APK”提示信息

Android Studio打包时&#xff0c;默认显示“Generate Signed APK”提示信息&#xff0c;如下图所示&#xff1a; 如果在打包时不显示“Generate Signed APK”提示信息&#xff0c;解决办法是&#xff1a; Android Studio菜单栏&#xff0c;“File->Settings->Appearan…

典型的列转行(sparkSQL)

数据 id,username,math,computer,english 1,huangbo,34,58,58 2,xuzheng,45,87,45 3,wangbaoqiang,76,34,89 编写 SQL&#xff0c;将其转换为下面这张表 id,username,course,score 1,huangbo,math,34 1,huangbo,computer,58 1,huangbo,english,58 2,xuzheng,math,45 2,xuzheng,…

42python数据分析numpy基础之trace计算对角线元素的和

python的numpy库的trace()函数&#xff0c;计算对角线元素的和。 用法 numpy.trace(a, offset0, axis10, axis21, dtypeNone, outNone)描述 numpy.trace(a)&#xff0c;返回数组a的对角线元素的和。 入参 a&#xff1a;必选&#xff0c;数组&#xff0c;列表&#xff0c;元…