summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2009-08-12 09:56:44 -0400
committerMike Lockwood <lockwood@android.com>2009-08-12 09:59:32 -0400
commit07a500f0de2243b832e258ed477652a10cbd2d08 (patch)
tree7ebbbcc116d05de1600da07f2555357cd6971560
parent2ec8458c5fd5b1bfad2d6e16b606f5acbcfa34cc (diff)
downloadframeworks_base-07a500f0de2243b832e258ed477652a10cbd2d08.zip
frameworks_base-07a500f0de2243b832e258ed477652a10cbd2d08.tar.gz
frameworks_base-07a500f0de2243b832e258ed477652a10cbd2d08.tar.bz2
BatteryService: Fix problems shutting down when the battery is dead:
Wait until system is booted before attempting to display the shutdown dialog. Use ShutdownActivity rather than attempting to run ShutdownThread in the battery service. Fix logic error (check !isPowered() instead of isPowered()) Signed-off-by: Mike Lockwood <lockwood@android.com>
-rw-r--r--services/java/com/android/server/BatteryService.java25
-rw-r--r--services/java/com/android/server/SystemServer.java4
2 files changed, 21 insertions, 8 deletions
diff --git a/services/java/com/android/server/BatteryService.java b/services/java/com/android/server/BatteryService.java
index 45c1e5c..26fee89 100644
--- a/services/java/com/android/server/BatteryService.java
+++ b/services/java/com/android/server/BatteryService.java
@@ -44,8 +44,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
-import com.android.internal.app.ShutdownThread;
-
/**
* <p>BatteryService monitors the charging status, and charge level of the device
@@ -176,6 +174,22 @@ class BatteryService extends Binder {
return mBatteryLevel;
}
+ void systemReady() {
+ // check our power situation now that it is safe to display the shutdown dialog.
+ shutdownIfNoPower();
+ }
+
+ private final void shutdownIfNoPower() {
+ // shut down gracefully if our battery is critically low and we are not powered.
+ // wait until the system has booted before attempting to display the shutdown dialog.
+ if (mBatteryLevel == 0 && !isPowered() && ActivityManagerNative.isSystemReady()) {
+ Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
+ intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ mContext.startActivity(intent);
+ }
+ }
+
private native void native_update();
private synchronized final void update() {
@@ -184,11 +198,8 @@ class BatteryService extends Binder {
boolean logOutlier = false;
long dischargeDuration = 0;
- // shut down gracefully if our battery is critically low and we are not powered
- if (mBatteryLevel == 0 && isPowered(0xffffffff)) {
- ShutdownThread.shutdown(mContext, false);
- }
-
+ shutdownIfNoPower();
+
mBatteryLevelCritical = mBatteryLevel <= CRITICAL_BATTERY_LEVEL;
if (mAcOnline) {
mPlugType = BatteryManager.BATTERY_PLUGGED_AC;
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index c30386e..8919ccc 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -84,6 +84,7 @@ class ServerThread extends Thread {
HardwareService hardware = null;
PowerManagerService power = null;
+ BatteryService battery = null;
IPackageManager pm = null;
Context context = null;
WindowManagerService wm = null;
@@ -132,7 +133,7 @@ class ServerThread extends Thread {
ActivityManagerService.installSystemProviders();
Log.i(TAG, "Starting Battery Service.");
- BatteryService battery = new BatteryService(context);
+ battery = new BatteryService(context);
ServiceManager.addService("battery", battery);
Log.i(TAG, "Starting Hardware Service.");
@@ -380,6 +381,7 @@ class ServerThread extends Thread {
} catch (RemoteException e) {
}
+ battery.systemReady();
Watchdog.getInstance().start();
Looper.loop();