都是修改framework下面的文件:
1、com.android.internal.policy.impl.GlobalActions
在items中添加如下参考代码,表示在系统power菜单中添加一个“重启”选项以及响应reboot事件:
new SinglePressAction(
com.android.internal.R.drawable.ic_lock_power_off,
R.string.global_action_power_reboot) {
public void onPress() {
ShutdownThread.reboot(mContext, null, true);
}
public boolean showDuringKeyguard() {
return true;
}
public boolean showBeforeProvisioning() {
return true;
}
});
2、 在com.android.internal.app.ShutdownThread类中添加相应的重启reboot处理事件。
类似于下面的代码:
/**
* Request a clean shutdown, waiting for subsystems to clean up their
* state etc. Must be called from a Looper thread in which its UI
* is shown.
*
* @param context Context used to display the shutdown progress dialog.
* @param confirm true if user confirmation is needed before shutting down.
* @param isReboot true if user confirmation is needed reboot and not shutdown.
*/
public static void shutdown(final Context context, boolean confirm,boolean isReboot) {
mReboot = isReboot ;
// ensure that only one thread is trying to power down.
// any additional calls are just returned
synchronized (sIsStartedGuard) {
if (sIsStarted) {
Log.d(TAG, "Request to shutdown already running, returning.");
return;
}
}
Log.d(TAG, "Notifying thread to start radio shutdown");
if (confirm) {
final AlertDialog dialog = new AlertDialog.Builder(context)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(mReboot?com.android.internal.R.string.global_action_power_reboot:com.android.internal.R.string.global_action_power_off)
.setMessage(mReboot?com.android.internal.R.string.reboot_confirm:com.android.internal.R.string.shutdown_confirm)
.setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
beginShutdownSequence(context);
}
})
.setNegativeButton(com.android.internal.R.string.no, null)
.create();
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
if (!context.getResources().getBoolean(
com.android.internal.R.bool.config_sf_slowBlur)) {
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
}
dialog.show();
} else {
beginShutdownSequence(context);
}
}