OSDN Git Service

add reboot item to power button dialog
authorYi Sun <beyounn@gmail.com>
Thu, 24 Sep 2009 23:36:41 +0000 (16:36 -0700)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Fri, 29 Oct 2010 07:45:11 +0000 (15:45 +0800)
core/java/com/android/internal/app/ShutdownThread.java
core/res/res/values/strings.xml

index a96253b..77d6b24 100644 (file)
@@ -17,6 +17,7 @@
  
 package com.android.internal.app;
 
+import java.io.*;
 import android.app.ActivityManagerNative;
 import android.app.IActivityManager;
 import android.app.ProgressDialog;
@@ -69,6 +70,7 @@ public final class ShutdownThread extends Thread {
     private PowerManager mPowerManager;
     private PowerManager.WakeLock mWakeLock;
     private Handler mHandler;
+    private static boolean mRebootReq;
     
     private ShutdownThread() {
     }
@@ -82,6 +84,11 @@ public final class ShutdownThread extends Thread {
      * @param confirm true if user confirmation is needed before shutting down.
      */
     public static void shutdown(final Context context, boolean confirm) {
+        shutdown(context, confirm, false);
+    }
+
+    public static void shutdown(final Context context,
+                                boolean confirm, boolean rebootonly) {
         // ensure that only one thread is trying to power down.
         // any additional calls are just returned
         synchronized (sIsStartedGuard){
@@ -92,19 +99,25 @@ public final class ShutdownThread extends Thread {
         }
 
         Log.d(TAG, "Notifying thread to start radio shutdown");
-
+        mRebootReq = rebootonly;
         if (confirm) {
             final AlertDialog dialog = new AlertDialog.Builder(context)
-                    .setIcon(android.R.drawable.ic_dialog_alert)
-                    .setTitle(com.android.internal.R.string.power_off)
-                    .setMessage(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();
+                .setIcon(android.R.drawable.ic_dialog_alert)
+                .setTitle(rebootonly ?
+                          com.android.internal.R.string.reboot :
+                          com.android.internal.R.string.power_off)
+                .setMessage(rebootonly ?
+                            com.android.internal.R.string.reboot_nb_confirm :
+                            com.android.internal.R.string.shutdown_nb_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)) {
@@ -139,8 +152,12 @@ 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(com.android.internal.R.string.power_off));
-        pd.setMessage(context.getText(com.android.internal.R.string.shutdown_progress));
+        pd.setTitle(context.getText(mRebootReq ?
+                                    com.android.internal.R.string.reboot :
+                                    com.android.internal.R.string.power_off));
+        pd.setMessage(context.getText(mRebootReq ?
+                                      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);
@@ -341,6 +358,13 @@ public final class ShutdownThread extends Thread {
 
         // Shutdown power
         Log.i(TAG, "Performing low-level shutdown...");
-        Power.shutdown();
+        if (mRebootReq)
+            try {
+                Power.reboot(null);
+            } catch (IOException e) {
+                Log.e(TAG, "can not reboot the machine " + e);
+            }
+        else
+            Power.shutdown();
     }
 }
index 86bfe94..e2c4acd 100644 (file)
     <!-- Button to turn off the phone, within the Phone Options dialog -->
     <string name="power_off">Power off</string>
 
+    <!-- Button to Reboot the device, within the power button Options dialog -->
+    <string name="reboot">Reboot</string>
+
     <!-- Shutdown Progress Dialog. This is shown if the user chooses to power off the phone. -->
     <string name="shutdown_progress">Shutting down\u2026</string>
 
+    <!-- Rebooting Progress Dialog. This is shown if the user chooses to reboot the device. -->
+    <string name="reboot_progress">Rebooting\u2026</string>
+
     <!-- Shutdown Confirmation Dialog.  When the user chooses to power off the phone, there will be a confirmation dialog.  This is the message. -->
     <string name="shutdown_confirm">Your phone will shut down.</string>
 
+    <!-- Shutdown Confirmation Dialog.  When the user chooses to power off the machine, there will be a confirmation dialog.  This is the message. -->
+    <string name="shutdown_nb_confirm">Your machine will shut down.</string>
+
+    <!-- Reboot Confirmation Dialog.  When the user chooses to reboot the machine, there will be a confirmation dialog.  This is the message. -->
+    <string name="reboot_nb_confirm">Your machine will reboot.</string>
+
     <!-- Recent Tasks dialog: title -->
     <string name="recent_tasks_title">Recent</string>
     <!-- Recent Tasks dialog: message when there are no recent applications -->
     <!-- Title of the Global Actions Dialog -->
     <string name="global_actions">Phone options</string>
 
+    <!-- Title of the Global Actions Dialog -->
+    <string name="global_nb_actions">Power button options</string>
+
     <!-- label for item that locks the phone in the phone options dialog -->
     <string name="global_action_lock">Screen lock</string>
 
     <!-- label for item that turns off power in phone options dialog -->
     <string name="global_action_power_off">Power off</string>
 
+    <!-- label for item that reboots the device in phone options dialog -->
+    <string name="global_action_reboot">Reboot</string>
+
     <!-- label for item that enables silent mode in phone options dialog -->
     <string name="global_action_toggle_silent_mode">Silent mode</string>