OSDN Git Service

Add API to compute charge time remaining.
authorMichael Wright <michaelwr@google.com>
Wed, 11 Apr 2018 22:06:36 +0000 (23:06 +0100)
committerMichael Wright <michaelwr@google.com>
Wed, 11 Apr 2018 22:47:31 +0000 (23:47 +0100)
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

api/current.txt
core/java/android/os/BatteryManager.java

index 423e0ae..a8280e0 100644 (file)
@@ -32053,6 +32053,7 @@ package android.os {
   }
 
   public class BatteryManager {
+    method public long computeChargeTimeRemaining();
     method public int getIntProperty(int);
     method public long getLongProperty(int);
     method public boolean isCharging();
index 6363161..954071a 100644 (file)
@@ -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();
+        }
+    }
 }