Android系统添加手机重启reboot选项


都是修改framework下面的文件:

1、com.Android.internal.policy.impl.GlobalActions

在items中添加如下参考代码,表示在系统power菜单中添加一个“重启”选项以及响应reboot事件:

  1. new SinglePressAction(   
  2.                         com.android.internal.R.drawable.ic_lock_power_off,   
  3.                         R.string.global_action_power_reboot) {   
  4.   
  5.                     public void onPress() {   
  6.                         ShutdownThread.reboot(mContext, nulltrue);   
  7.                     }   
  8.   
  9.                     public boolean showDuringKeyguard() {   
  10.                         return true;   
  11.                     }   
  12.   
  13.                     public boolean showBeforeProvisioning() {   
  14.                         return true;   
  15.                     }   
  16.                 });  

2、 在com.android.internal.app.ShutdownThread类中添加相应的重启reboot处理事件。

类似于下面的代码:

  1. /**  
  2.      * Request a clean shutdown, waiting for subsystems to clean up their  
  3.      * state etc.  Must be called from a Looper thread in which its UI  
  4.      * is shown.  
  5.      *  
  6.      * @param context Context used to display the shutdown progress dialog.  
  7.      * @param confirm true if user confirmation is needed before shutting down.  
  8.      * @param isReboot true if user confirmation is needed reboot and not shutdown.  
  9.      */  
  10.     public static void shutdown(final Context context, boolean confirm,boolean isReboot) {   
  11.         mReboot = isReboot ;   
  12.         // ensure that only one thread is trying to power down.   
  13.         // any additional calls are just returned   
  14.         synchronized (sIsStartedGuard) {   
  15.             if (sIsStarted) {   
  16.                 Log.d(TAG, "Request to shutdown already running, returning.");   
  17.                 return;   
  18.             }   
  19.         }   
  20.   
  21.         Log.d(TAG, "Notifying thread to start radio shutdown");   
  22.   
  23.         if (confirm) {   
  24.             final AlertDialog dialog = new AlertDialog.Builder(context)   
  25.                     .setIcon(android.R.drawable.ic_dialog_alert)   
  26.                     .setTitle(mReboot?com.android.internal.R.string.global_action_power_reboot:com.android.internal.R.string.global_action_power_off)   
  27.                     .setMessage(mReboot?com.android.internal.R.string.reboot_confirm:com.android.internal.R.string.shutdown_confirm)   
  28.                     .setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() {   
  29.                         public void onClick(DialogInterface dialog, int which) {   
  30.                             beginShutdownSequence(context);   
  31.                         }   
  32.                     })   
  33.                     .setNegativeButton(com.android.internal.R.string.no, null)   
  34.                     .create();   
  35.             dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);   
  36.             if (!context.getResources().getBoolean(   
  37.                     com.android.internal.R.bool.config_sf_slowBlur)) {   
  38.                 dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);   
  39.             }   
  40.             dialog.show();   
  41.         } else {   
  42.             beginShutdownSequence(context);   
  43.         }   
  44.     }  

更多Android相关信息见Android 专题页面 http://www.bkjia.com/topicnews.aspx?tid=11

相关内容