都是修改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);
- }
- }
更多Android相關信息見Android 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=11