summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorMichael Wright <michaelwr@google.com>2018-04-11 23:06:36 +0100
committerMichael Wright <michaelwr@google.com>2018-04-11 23:47:31 +0100
commit928167e04475d45413bef579b6b03c6c3eca591f (patch)
tree52c9013fbf54fb081e23b1aa0600756f3821ce83 /core/java
parent8a3890de72a83920eefb9f66c0f0fabaa515cca3 (diff)
Add API to compute charge time remaining.
This is so unbundled applications (e.g. dreams) can present a charge time indicator that is in sync with the rest of the system. Bug: 77919650 Test: manual Change-Id: I7d62dea4fd49eb173b4f052a0fc36f4e7ce5b6bb
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/os/BatteryManager.java16
1 files changed, 16 insertions, 0 deletions
diff --git a/core/java/android/os/BatteryManager.java b/core/java/android/os/BatteryManager.java
index 63631618856a..954071a0ee97 100644
--- a/core/java/android/os/BatteryManager.java
+++ b/core/java/android/os/BatteryManager.java
@@ -353,4 +353,20 @@ public class BatteryManager {
public static boolean isPlugWired(int plugType) {
return plugType == BATTERY_PLUGGED_USB || plugType == BATTERY_PLUGGED_AC;
}
+
+ /**
+ * Compute an approximation for how much time (in milliseconds) remains until the battery is
+ * fully charged. Returns -1 if no time can be computed: either there is not enough current
+ * data to make a decision or the battery is currently discharging.
+ *
+ * @return how much time is left, in milliseconds, until the battery is fully charged or -1 if
+ * the computation fails
+ */
+ public long computeChargeTimeRemaining() {
+ try {
+ return mBatteryStats.computeChargeTimeRemaining();
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
}