Merge "BatteryManager: battery property query API update" into lmp-preview-dev
diff --git a/api/current.txt b/api/current.txt
index 1c4254e..090c7b5 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -20523,7 +20523,8 @@
public class BatteryManager {
ctor public BatteryManager();
- method public android.os.BatteryProperty getProperty(int) throws android.os.RemoteException;
+ method public int getIntProperty(int);
+ method public long getLongProperty(int);
field public static final int BATTERY_HEALTH_COLD = 7; // 0x7
field public static final int BATTERY_HEALTH_DEAD = 4; // 0x4
field public static final int BATTERY_HEALTH_GOOD = 2; // 0x2
@@ -20534,6 +20535,11 @@
field public static final int BATTERY_PLUGGED_AC = 1; // 0x1
field public static final int BATTERY_PLUGGED_USB = 2; // 0x2
field public static final int BATTERY_PLUGGED_WIRELESS = 4; // 0x4
+ field public static final int BATTERY_PROPERTY_CAPACITY = 4; // 0x4
+ field public static final int BATTERY_PROPERTY_CHARGE_COUNTER = 1; // 0x1
+ field public static final int BATTERY_PROPERTY_CURRENT_AVERAGE = 3; // 0x3
+ field public static final int BATTERY_PROPERTY_CURRENT_NOW = 2; // 0x2
+ field public static final int BATTERY_PROPERTY_ENERGY_COUNTER = 5; // 0x5
field public static final int BATTERY_STATUS_CHARGING = 2; // 0x2
field public static final int BATTERY_STATUS_DISCHARGING = 3; // 0x3
field public static final int BATTERY_STATUS_FULL = 5; // 0x5
@@ -20551,20 +20557,6 @@
field public static final java.lang.String EXTRA_VOLTAGE = "voltage";
}
- public class BatteryProperty implements android.os.Parcelable {
- method public int describeContents();
- method public int getInt();
- method public long getLong();
- method public void readFromParcel(android.os.Parcel);
- method public void writeToParcel(android.os.Parcel, int);
- field public static final int CAPACITY = 4; // 0x4
- field public static final int CHARGE_COUNTER = 1; // 0x1
- field public static final android.os.Parcelable.Creator CREATOR;
- field public static final int CURRENT_AVERAGE = 3; // 0x3
- field public static final int CURRENT_NOW = 2; // 0x2
- field public static final int ENERGY_COUNTER = 5; // 0x5
- }
-
public class Binder implements android.os.IBinder {
ctor public Binder();
method public void attachInterface(android.os.IInterface, java.lang.String);
diff --git a/core/java/android/os/BatteryManager.java b/core/java/android/os/BatteryManager.java
index 32050dc..537e993 100644
--- a/core/java/android/os/BatteryManager.java
+++ b/core/java/android/os/BatteryManager.java
@@ -128,29 +128,97 @@
public static final int BATTERY_PLUGGED_ANY =
BATTERY_PLUGGED_AC | BATTERY_PLUGGED_USB | BATTERY_PLUGGED_WIRELESS;
+ /*
+ * Battery property identifiers. These must match the values in
+ * frameworks/native/include/batteryservice/BatteryService.h
+ */
+ /** Battery capacity in microampere-hours, as an integer. */
+ public static final int BATTERY_PROPERTY_CHARGE_COUNTER = 1;
+
+ /**
+ * 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 BATTERY_PROPERTY_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 BATTERY_PROPERTY_CURRENT_AVERAGE = 3;
+
+ /**
+ * Remaining battery capacity as an integer percentage of total capacity
+ * (with no fractional part).
+ */
+ public static final int BATTERY_PROPERTY_CAPACITY = 4;
+
+ /**
+ * Battery remaining energy in nanowatt-hours, as a long integer.
+ */
+ public static final int BATTERY_PROPERTY_ENERGY_COUNTER = 5;
+
private IBatteryPropertiesRegistrar mBatteryPropertiesRegistrar;
/**
- * Return the requested battery property.
+ * Query a battery property from the batteryproperties service.
*
- * @param id identifier from {@link BatteryProperty} of the requested property
- * @return a {@link BatteryProperty} object that returns the property value, or null on error
+ * Returns the requested value, or Long.MIN_VALUE if property not
+ * supported on this system or on other error.
*/
- public BatteryProperty getProperty(int id) throws RemoteException {
+ private long queryProperty(int id) {
+ long ret;
+
if (mBatteryPropertiesRegistrar == null) {
IBinder b = ServiceManager.getService("batteryproperties");
mBatteryPropertiesRegistrar =
IBatteryPropertiesRegistrar.Stub.asInterface(b);
if (mBatteryPropertiesRegistrar == null)
- return null;
+ return Long.MIN_VALUE;
}
- BatteryProperty prop = new BatteryProperty();
- if ((mBatteryPropertiesRegistrar.getProperty(id, prop) == 0) &&
- (prop.getLong() != Long.MIN_VALUE))
- return prop;
- else
- return null;
+ try {
+ BatteryProperty prop = new BatteryProperty();
+
+ if (mBatteryPropertiesRegistrar.getProperty(id, prop) == 0)
+ ret = prop.getLong();
+ else
+ ret = Long.MIN_VALUE;
+ } catch (RemoteException e) {
+ ret = Long.MIN_VALUE;
+ }
+
+ return ret;
+ }
+
+ /**
+ * Return the value of a battery property of integer type. If the
+ * platform does not provide the property queried, this value will
+ * be Integer.MIN_VALUE.
+ *
+ * @param id identifier of the requested property
+ *
+ * @return the property value, or Integer.MIN_VALUE if not supported.
+ */
+ public int getIntProperty(int id) {
+ return (int)queryProperty(id);
+ }
+
+ /**
+ * Return the value of a battery property of long type If the
+ * platform does not provide the property queried, this value will
+ * be Long.MIN_VALUE.
+ *
+ * @param id identifier of the requested property
+ *
+ * @return the property value, or Long.MIN_VALUE if not supported.
+ */
+ public long getLongProperty(int id) {
+ return queryProperty(id);
}
}
diff --git a/core/java/android/os/BatteryProperty.java b/core/java/android/os/BatteryProperty.java
index 27dad4f..84119bd 100644
--- a/core/java/android/os/BatteryProperty.java
+++ b/core/java/android/os/BatteryProperty.java
@@ -20,44 +20,13 @@
/**
* Battery properties that may be queried using
- * {@link BatteryManager#getProperty
* BatteryManager.getProperty()}
*/
+
+/**
+ * @hide
+ */
public class BatteryProperty implements Parcelable {
- /*
- * Battery property identifiers. These must match the values in
- * frameworks/native/include/batteryservice/BatteryService.h
- */
- /** Battery capacity in microampere-hours, as an integer. */
- public static final int CHARGE_COUNTER = 1;
-
- /**
- * 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;
-
- /**
- * Battery remaining energy in nanowatt-hours, as a long integer.
- */
- public static final int ENERGY_COUNTER = 5;
-
private long mValueLong;
/**
@@ -68,30 +37,12 @@
}
/**
- * 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 (int)mValueLong;
- }
-
- /**
- * Return the value of a property of long type previously queried
- * via {@link BatteryManager#getProperty
- * BatteryManager.getProperty()}. If the platform does
- * not provide the property queried, this value will be
- * Long.MIN_VALUE.
- *
- * @return The queried property value, or Long.MIN_VALUE if not supported.
+ * @hide
*/
public long getLong() {
return mValueLong;
}
+
/*
* Parcel read/write code must be kept in sync with
* frameworks/native/services/batteryservice/BatteryProperty.cpp