From fda6fae156e31a287e3cfbf66e51ea1405cdf479 Mon Sep 17 00:00:00 2001 From: Cliff Spradlin Date: Wed, 22 Oct 2008 20:29:16 -0700 Subject: [PATCH] Added broadcasts for external power events. --- core/java/android/content/Intent.java | 20 ++++++++++++++++++++ services/java/com/android/server/BatteryService.java | 10 ++++++++++ 2 files changed, 30 insertions(+) diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java index c76158c1adb0..598e0e8944e2 100644 --- a/core/java/android/content/Intent.java +++ b/core/java/android/content/Intent.java @@ -507,6 +507,8 @@ import java.util.Set; *
  • {@link #ACTION_PACKAGE_REMOVED} *
  • {@link #ACTION_UID_REMOVED} *
  • {@link #ACTION_BATTERY_CHANGED} + *
  • {@link #ACTION_POWER_CONNECTED} + *
  • {@link #ACTION_POWER_DISCONNECTED} * * *

    Standard Categories

    @@ -1178,6 +1180,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 608299c8ce6f..faa820829750 100644 --- a/services/java/com/android/server/BatteryService.java +++ b/services/java/com/android/server/BatteryService.java @@ -149,6 +149,16 @@ class BatteryService extends Binder { mBatteryLevel, mBatteryVoltage, mBatteryTemperature); } + // 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) { + mContext.sendBroadcast(new Intent(Intent.ACTION_POWER_CONNECTED)); + } + else if (mPlugType == 0 && mLastPlugType != 0) { + mContext.sendBroadcast(new Intent(Intent.ACTION_POWER_DISCONNECTED)); + } + mLastBatteryStatus = mBatteryStatus; mLastBatteryHealth = mBatteryHealth; mLastBatteryPresent = mBatteryPresent; -- 2.11.0