1, 添加reboot

      添加reboot可以仿照power off 来写

     首先涉及到的几个java文件,文件不多,大家可以先看一下

       frameworks/base/core/java/android/view/WindowManagerPolicy.java 

       frameworks/base/policy/src/com/android/internal/policy/impl/GlobalActions.java 

      frameworks/base/services/core/java/com/android/server/power/ShutdownThread.java 

       frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java 


WindowManagerPolicy.java 文件可以模仿关机写一个接口

         public void shutdown(boolean confirm);
        public void reboot(boolean confirm);
         public void rebootSafeMode(boolean confirm);


GlobalActions.java 文件修改长按power键弹出框的显示列表 直接上代码

private static final String GLOBAL_ACTION_KEY_POWER = "power";
+    private static final String GLOBAL_ACTION_KEY_REBOOT = "reboot";
     private static final String GLOBAL_ACTION_KEY_AIRPLANE = "airplane";
     private static final String GLOBAL_ACTION_KEY_BUGREPORT = "bugreport";
     private static final String GLOBAL_ACTION_KEY_SILENT = "silent";


添加重启选项

 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)) {
                 if (Settings.Global.getInt(mContext.getContentResolver(),


+    private final class RebootAction extends SinglePressAction {
+        private RebootAction() {
+            super(com.android.internal.R.drawable.ic_lock_power_reboot,
+                R.string.global_action_power_reboot);
+        }
+
+        @Override
+        public boolean showDuringKeyguard() {
+            return true;
+        }
+
+        @Override
+        public boolean showBeforeProvisioning() {
+            return true;
+        }
 
+        @Override
+        public void onPress() {
+            // reboot by making sure radio and power are handled accordingly.
+            mWindowManagerFuncs.reboot(false /* confirm */);
+        }
+    }


显示飞行模式

  private void onAirplaneModeChanged() {
         // Let the service state callbacks handle the state.
+        if (!mHasTelephony) return;
 
         boolean airplaneModeOn = Settings.Global.getInt(
                 mContext.getContentResolver(),

这里的常量字符是和config.xml里面对应的,如果config.xml里面配置了相应的字符串,列表就会显示对应的项

 
         power
+ reboot
+ airplane   
         bugreport
         users
     



ShutdownThread.java 文件修改的是点击关机或重启的时候显示字串


         final int resourceId = mRebootSafeMode
                 ? com.android.internal.R.string.reboot_safemode_confirm
                 : (longPressBehavior == 2

+                        ? (mReboot ? com.android.internal.R.string.reboot_confirm_question : com.android.internal.R.string.shutdown_confirm_question)
+                        : (mReboot ? com.android.internal.R.string.reboot_confirm : com.android.internal.R.string.shutdown_confirm));
 
         Log.d(TAG, "Notifying thread to start shutdown longPressBehavior=" + longPressBehavior);
 
@@ -136,10 +137,13 @@ public final class ShutdownThread extends Thread {
             if (sConfirmDialog != null) {
                 sConfirmDialog.dismiss();
             }

             sConfirmDialog = new AlertDialog.Builder(context)
                     .setTitle(mRebootSafeMode
                             ? com.android.internal.R.string.reboot_safemode_title

+                            : (mReboot
+     ? com.android.internal.R.string.reboot_title
+     :com.android.internal.R.string.power_off))
                     .setMessage(resourceId)
                     .setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() {
                         public void onClick(DialogInterface dialog, int which) {
@@ -220,8 +224,8 @@ public final class ShutdownThread extends Thread {
         // throw up an indeterminate system dialog to indicate radio is
         // shutting down.
         ProgressDialog pd = new ProgressDialog(context);

+        pd.setTitle(context.getText(mReboot ? com.android.internal.R.string.reboot_title : com.android.internal.R.string.power_off));
+        pd.setMessage(context.getText(mReboot ? com.android.internal.R.string.reboot_progress : com.android.internal.R.string.shutdown_progress));
         pd.setIndeterminate(true);
         pd.setCancelable(false);
         pd.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);



WindowManagerService.java 修改

 
+    @Override
+    public void reboot(boolean confirm) {
+        ShutdownThread.reboot(mContext, null, confirm);
+    }
+


更多相关文章

  1. Android 在xml布局配置文件中给Button按钮添加事件
  2. Android在SDcard建文件夹(在Android中移动文件必用)
  3. Android Studio 配置快捷方式生成JNI头文件的方法
  4. android 安装文件例子
  5. android 读取DDMS里的文件时打不开,解决方法
  6. android配置文件详解
  7. 简单的Android日志文件记录类
  8. Android上传文件,客户端+服务器源码

随机推荐

  1. Android(安卓)Volley框架
  2. 透明Dialog的实现.
  3. Android(安卓)9 使用okhttp3报错 CLEARTE
  4. android的一些知识小记
  5. android osmdroid 实现谷歌地图之定位 替
  6. Android(安卓)解决打包时提示65536问题
  7. Android学习笔记(13):帧布局FrameLayout
  8. AndroidO SystemUI-QuickSettings
  9. 深入理解Android中的Handler机制
  10. ScrollView嵌套Linearlayout显示不全的解