diff options
| author | 2014-06-05 14:49:28 -0700 | |
|---|---|---|
| committer | 2014-06-05 18:10:46 -0700 | |
| commit | 5fde3ff375e6cec3c11ddef7a4650d5f5f4942d1 (patch) | |
| tree | 5e81a011539af2abd87dd14c2babc73f5c5156f4 | |
| parent | 03b62b3c7ff57f44a9142bac48603656dfb550ed (diff) | |
BatteryManager: battery property query API update
Move battery property value accessors to BatteryManager.
Hide BatteryProperty class.
Bug: 15191190
Change-Id: Ic021e6e28a8bc30c145ccc31b3a3446ba82d2004
| -rw-r--r-- | api/current.txt | 22 | ||||
| -rw-r--r-- | core/java/android/os/BatteryManager.java | 90 | ||||
| -rw-r--r-- | core/java/android/os/BatteryProperty.java | 61 |
3 files changed, 92 insertions, 81 deletions
diff --git a/api/current.txt b/api/current.txt index 79fb8dfc50bf..ab3dc3e8884b 100644 --- a/api/current.txt +++ b/api/current.txt @@ -20524,7 +20524,8 @@ package android.os { 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 @@ -20535,6 +20536,11 @@ package android.os { 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 @@ -20552,20 +20558,6 @@ package android.os { 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 32050dc2629d..537e993e3be9 100644 --- a/core/java/android/os/BatteryManager.java +++ b/core/java/android/os/BatteryManager.java @@ -128,29 +128,97 @@ public class BatteryManager { 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 27dad4f24173..84119bdc126d 100644 --- a/core/java/android/os/BatteryProperty.java +++ b/core/java/android/os/BatteryProperty.java @@ -20,44 +20,13 @@ import android.os.Parcelable; /** * 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 - */ - /** 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; +/** + * @hide + */ +public class BatteryProperty implements Parcelable { private long mValueLong; /** @@ -68,30 +37,12 @@ public class BatteryProperty implements Parcelable { } /** - * 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 |