一、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; // 0xff
field public static final int KEYCODE_U = 49; // 0x31
field 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; // 0x132
field public static final int KEYCODE_V = 50; // 0x32
field public static final int KEYCODE_VOICE_ASSIST = 231; // 0xe7
field 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 POUND
key 580 APP_SWITCH
key 582 VOICE_ASSIST
+key 744 USERKEY
+key 745 USERKEY_LP
+
# Keys defined by HID usages
key usage 0x0c006F BRIGHTNESS_UP
key 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 }
};