summaryrefslogtreecommitdiffstats
path: root/core/java/android/os
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android/os')
-rw-r--r--core/java/android/os/BatteryManager.java34
-rw-r--r--core/java/android/os/BatteryProperty.java63
2 files changed, 87 insertions, 10 deletions
diff --git a/core/java/android/os/BatteryManager.java b/core/java/android/os/BatteryManager.java
index 2e38960..f339e52 100644
--- a/core/java/android/os/BatteryManager.java
+++ b/core/java/android/os/BatteryManager.java
@@ -16,9 +16,15 @@
package android.os;
+import android.os.BatteryProperty;
+import android.os.IBatteryPropertiesRegistrar;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+
/**
* The BatteryManager class contains strings and constants used for values
- * in the {@link android.content.Intent#ACTION_BATTERY_CHANGED} Intent.
+ * in the {@link android.content.Intent#ACTION_BATTERY_CHANGED} Intent, and
+ * provides a method for querying battery and charging properties.
*/
public class BatteryManager {
/**
@@ -121,4 +127,30 @@ public class BatteryManager {
/** @hide */
public static final int BATTERY_PLUGGED_ANY =
BATTERY_PLUGGED_AC | BATTERY_PLUGGED_USB | BATTERY_PLUGGED_WIRELESS;
+
+ private IBatteryPropertiesRegistrar mBatteryPropertiesRegistrar;
+
+ /**
+ * Return the requested battery property.
+ *
+ * @param id identifier from {@link BatteryProperty} of the requested property
+ * @return a {@link BatteryProperty} object that returns the property value, or null on error
+ */
+ public BatteryProperty getProperty(int id) throws RemoteException {
+ if (mBatteryPropertiesRegistrar == null) {
+ IBinder b = ServiceManager.getService("batteryproperties");
+ mBatteryPropertiesRegistrar =
+ IBatteryPropertiesRegistrar.Stub.asInterface(b);
+
+ if (mBatteryPropertiesRegistrar == null)
+ return null;
+ }
+
+ BatteryProperty prop = new BatteryProperty(Integer.MIN_VALUE);
+ if ((mBatteryPropertiesRegistrar.getProperty(id, prop) == 0) &&
+ (prop.getInt() != Integer.MIN_VALUE))
+ return prop;
+ else
+ return null;
+ }
}
diff --git a/core/java/android/os/BatteryProperty.java b/core/java/android/os/BatteryProperty.java
index 76b0dc4..ec73952 100644
--- a/core/java/android/os/BatteryProperty.java
+++ b/core/java/android/os/BatteryProperty.java
@@ -19,22 +19,67 @@ import android.os.Parcel;
import android.os.Parcelable;
/**
- * {@hide}
+ * Battery properties that may be queried using
+ * {@link BatteryManager#getProperty
+ * BatteryManager.getProperty()}
*/
public class BatteryProperty implements Parcelable {
/*
* Battery property identifiers. These must match the values in
* frameworks/native/include/batteryservice/BatteryService.h
*/
- public static final int BATTERY_PROP_CHARGE_COUNTER = 1;
- public static final int BATTERY_PROP_CURRENT_NOW = 2;
- public static final int BATTERY_PROP_CURRENT_AVG = 3;
- public static final int BATTERY_PROP_CAPACITY = 4;
+ /** Battery capacity in microampere-hours, as an integer. */
+ public static final int CHARGE_COUNTER = 1;
- public int valueInt;
+ /**
+ * Instantaneous battery current in microamperes, as an integer. Positive
+ * values indicate net current entering the battery from a charge source,
+ * negative values indicate net current discharging from the battery.
+ */
+ public static final int CURRENT_NOW = 2;
+
+ /**
+ * Average battery current in microamperes, as an integer. Positive
+ * values indicate net current entering the battery from a charge source,
+ * negative values indicate net current discharging from the battery.
+ * The time period over which the average is computed may depend on the
+ * fuel gauge hardware and its configuration.
+ */
+ public static final int CURRENT_AVERAGE = 3;
+ /**
+ * Remaining battery capacity as an integer percentage of total capacity
+ * (with no fractional part).
+ */
+ public static final int CAPACITY = 4;
+
+ private int mValueInt;
+
+ /**
+ * @hide
+ */
+ public BatteryProperty(int value) {
+ mValueInt = value;
+ }
+
+ /**
+ * @hide
+ */
public BatteryProperty() {
- valueInt = Integer.MIN_VALUE;
+ mValueInt = Integer.MIN_VALUE;
+ }
+
+ /**
+ * Return the value of a property of integer type previously queried
+ * via {@link BatteryManager#getProperty
+ * BatteryManager.getProperty()}. If the platform does
+ * not provide the property queried, this value will be
+ * Integer.MIN_VALUE.
+ *
+ * @return The queried property value, or Integer.MIN_VALUE if not supported.
+ */
+ public int getInt() {
+ return mValueInt;
}
/*
@@ -47,11 +92,11 @@ public class BatteryProperty implements Parcelable {
}
public void readFromParcel(Parcel p) {
- valueInt = p.readInt();
+ mValueInt = p.readInt();
}
public void writeToParcel(Parcel p, int flags) {
- p.writeInt(valueInt);
+ p.writeInt(mValueInt);
}
public static final Parcelable.Creator<BatteryProperty> CREATOR