From 06ba55476ee9703c876d223cd41bd73c5f85f42d Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Thu, 9 Apr 2009 16:03:56 -0700 Subject: [PATCH] Integrate new power connnect/disconnect broadcasts Two new broadcasts, Intent.ACTION_POWER_CONNECTED and Intent.ACTION_POWER_CONNECTED, that are issued when the device is plugged and unplugged from USB or AC power. This pulls two changes from the open-source Gerrit repo into the internal Donut codeline: 1241 fda6fae Added broadcasts for external power events. 9491 37f8ca1 Fix system service crash when booting while on battery power The current.xml API description has also been updated to include the new Intent fields; the new API was approved in the original OSS change. --- api/current.xml | 22 ++++++++++++++++++++++ core/java/android/content/Intent.java | 20 ++++++++++++++++++++ .../java/com/android/server/BatteryService.java | 14 ++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/api/current.xml b/api/current.xml index 66128c53b382..d14c9b9b6e81 100644 --- a/api/current.xml +++ b/api/current.xml @@ -28335,6 +28335,28 @@ visibility="public" > + + + + {@link #ACTION_PACKAGE_DATA_CLEARED} *
  • {@link #ACTION_UID_REMOVED} *
  • {@link #ACTION_BATTERY_CHANGED} + *
  • {@link #ACTION_POWER_CONNECTED} + *
  • {@link #ACTION_POWER_DISCONNECTED} * * *

    Standard Categories

    @@ -1250,6 +1252,24 @@ public class Intent implements Parcelable { @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_BATTERY_LOW = "android.intent.action.BATTERY_LOW"; /** + * Broadcast Action: External power has been connected to the device. + * This is intended for applications that wish to register specifically to this notification. + * Unlike ACTION_BATTERY_CHANGED, applications will be woken for this and so do not have to + * stay active to receive this notification. This action can be used to implement actions + * that wait until power is available to trigger. + */ + @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) + public static final String ACTION_POWER_CONNECTED = "android.intent.action.ACTION_POWER_CONNECTED"; + /** + * Broadcast Action: External power has been removed from the device. + * This is intended for applications that wish to register specifically to this notification. + * Unlike ACTION_BATTERY_CHANGED, applications will be woken for this and so do not have to + * stay active to receive this notification. This action can be used to implement actions + * that wait until power is available to trigger. + */ + @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) + public static final String ACTION_POWER_DISCONNECTED = "android.intent.action.ACTION_POWER_DISCONNECTED"; + /** * Broadcast Action: Indicates low memory condition on the device */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) diff --git a/services/java/com/android/server/BatteryService.java b/services/java/com/android/server/BatteryService.java index 15eafcf19615..90d8c9d4ca5d 100644 --- a/services/java/com/android/server/BatteryService.java +++ b/services/java/com/android/server/BatteryService.java @@ -247,6 +247,20 @@ class BatteryService extends Binder { logOutlier = true; } + // 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. + 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); + } + 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); + } + mLastBatteryStatus = mBatteryStatus; mLastBatteryHealth = mBatteryHealth; mLastBatteryPresent = mBatteryPresent; -- 2.11.0