现在长按Power键只有一个关机键,需要添加一个重启,以下是我的添加步骤:
1.在frameworks/base/core/res/res/values/config.xml里添加重启:
- <!-- Defines the default set of global actions. Actions may still be disabled or hidden based
- on the current state of the device.
- Each item must be one of the following strings:
- "power" = Power off
- "settings" = An action to launch settings
- "airplane" = Airplane mode toggle
- "bugreport" = Take bug report, if available
- "silent" = silent mode
- "users" = list of users
- -->
- <string-array translatable="false" name="config_globalActionsList">
- <item>power</item>
- <item>reboot</item>
- <item>bugreport</item>
- <item>users</item>
- </string-array>
2.添加中英文的重启string:
frameworks/base/core/res/res/values/strings.xml
frameworks/base/core/res/res/values-zh-rCN/strings.xml
3.修改GlobalActions:
frameworks/base/policy/src/com/Android/internal/policy/impl/GlobalActions.Java
- --- a/frameworks/base/policy/src/com/android/internal/policy/impl/GlobalActions.java
- +++ b/frameworks/base/policy/src/com/android/internal/policy/impl/GlobalActions.java
- @@ -107,6 +107,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
- private static final String GLOBAL_ACTION_KEY_USERS = "users";
- private static final String GLOBAL_ACTION_KEY_SETTINGS = "settings";
- private static final String GLOBAL_ACTION_KEY_LOCKDOWN = "lockdown";
- + private static final String GLOBAL_ACTION_KEY_REBOOT = "reboot";
-
- private final Context mContext;
- private final WindowManagerFuncs mWindowManagerFuncs;
- @@ -306,6 +307,8 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
- }
- if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {
- mItems.add(new PowerAction());
- + } else if(GLOBAL_ACTION_KEY_REBOOT.equals(actionKey)){
- + mItems.add(new RebootAction());
- } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
- mItems.add(mAirplaneModeOn);
- } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
- @@ -371,7 +374,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
-
- @Override
- public boolean onLongPress() {
- - mWindowManagerFuncs.rebootSafeMode(true);
- +
- return true;
- }
-
- @@ -392,6 +395,42 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
- }
- }
-
- +
- + private final class RebootAction extends SinglePressAction implements LongPressAction {
- + private RebootAction() {
- + super(com.android.internal.R.drawable.ic_lock_power_off,
- + R.string.global_action_reboot);
- + }
- +
- + @Override
- + public boolean onLongPress() {
- +
- + return true;
- + }
- +
- + @Override
- + public boolean showDuringKeyguard() {
- + return true;
- + }
- +
- + @Override
- + public boolean showBeforeProvisioning() {
- + return true;
- + }
- +
- + @Override
- + public void onPress() {
- + try {
- + Intent intent = new Intent(Intent.ACTION_REBOOT);
- + intent.putExtra("nowait", 1);
- + intent.putExtra("interval", 1);
- + intent.putExtra("window", 0);
- + mContext.sendBroadcast(intent);
- + } catch (Exception e) {
- + }
- + }
- + }
- +
- private Action getBugReportAction() {
- return new SinglePressAction(com.android.internal.R.drawable.ic_lock_bugreport,
- R.string.bugreport_title) {
可以看到onPress()中是对重启的实现:
- Intent intent = new Intent(Intent.ACTION_REBOOT);
- intent.putExtra("nowait", 1);
- intent.putExtra("interval", 1);
- intent.putExtra("window", 0);
- mContext.sendBroadcast(intent);
Done!
修改图标: