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; // 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_VIDEO_APP_1 = 289; // 0x121
field 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_SWITCH
key 582 VOICE_ASSIST
# Linux KEY_ASSISTANT
key 583 ASSIST
+key 744 USERKEY
+key 745 USERKEY_LP
# Keys defined by HID usages
key 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.