From 93dc9fe96192dbe6f974ca5d1c7c1102eb4b325a Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Thu, 16 Jul 2009 13:25:49 -0700 Subject: [PATCH] Send all battery broadcasts with REGISTERED_ONLY_BEFORE_BOOT The "low" and "okay" broadcasts were not being sent with this flag, so that if the device had booted in a low battery state, the battery service would crash due to an illegal-state exception. This fixes bug b/1985606 --- .../com/android/server/BatteryService.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/services/java/com/android/server/BatteryService.java b/services/java/com/android/server/BatteryService.java index 5cdce5b3b63f4..a682fcb444ba7 100644 --- a/services/java/com/android/server/BatteryService.java +++ b/services/java/com/android/server/BatteryService.java @@ -254,15 +254,15 @@ class BatteryService extends Binder { // Separate broadcast is sent for power connected / not connected // since the standard intent will not wake any applications and some // applications may want to have smart behavior based on this. + Intent statusIntent = new Intent(); + statusIntent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); if (mPlugType != 0 && mLastPlugType == 0) { - Intent intent = new Intent(Intent.ACTION_POWER_CONNECTED); - intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); - mContext.sendBroadcast(intent); + statusIntent.setAction(Intent.ACTION_POWER_CONNECTED); + mContext.sendBroadcast(statusIntent); } else if (mPlugType == 0 && mLastPlugType != 0) { - Intent intent = new Intent(Intent.ACTION_POWER_DISCONNECTED); - intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); - mContext.sendBroadcast(intent); + statusIntent.setAction(Intent.ACTION_POWER_DISCONNECTED); + mContext.sendBroadcast(statusIntent); } final boolean plugged = mPlugType != BATTERY_PLUGGED_NONE; @@ -289,10 +289,12 @@ class BatteryService extends Binder { sendIntent(); if (sendBatteryLow) { mSentLowBatteryBroadcast = true; - mContext.sendBroadcast(new Intent(Intent.ACTION_BATTERY_LOW)); + statusIntent.setAction(Intent.ACTION_BATTERY_LOW); + mContext.sendBroadcast(statusIntent); } else if (mSentLowBatteryBroadcast && mLastBatteryLevel >= BATTERY_LEVEL_CLOSE_WARNING) { mSentLowBatteryBroadcast = false; - mContext.sendBroadcast(new Intent(Intent.ACTION_BATTERY_OKAY)); + statusIntent.setAction(Intent.ACTION_BATTERY_OKAY); + mContext.sendBroadcast(statusIntent); } // This needs to be done after sendIntent() so that we get the lastest battery stats.