Loading core/java/com/android/internal/app/IBatteryStats.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -133,7 +133,7 @@ interface IBatteryStats { void noteNetworkStatsEnabled(); void noteDeviceIdleMode(int mode, String activeReason, int activeUid); void setBatteryState(int status, int health, int plugType, int level, int temp, int volt, int chargeUAh, int chargeFullUAh); int chargeUAh, int chargeFullUAh, long chargeTimeToFullSeconds); @UnsupportedAppUsage long getAwakeTimeBattery(); long getAwakeTimePlugged(); Loading core/java/com/android/internal/os/BatteryStatsImpl.java +9 −14 Original line number Diff line number Diff line Loading @@ -996,6 +996,8 @@ public class BatteryStatsImpl extends BatteryStats { private int mMinLearnedBatteryCapacity = -1; private int mMaxLearnedBatteryCapacity = -1; private long mBatteryTimeToFullSeconds = -1; private long[] mCpuFreqs; @VisibleForTesting Loading Loading @@ -12218,7 +12220,7 @@ public class BatteryStatsImpl extends BatteryStats { @GuardedBy("this") public void setBatteryStateLocked(final int status, final int health, final int plugType, final int level, /* not final */ int temp, final int volt, final int chargeUAh, final int chargeFullUAh) { final int chargeFullUAh, final long chargeTimeToFullSeconds) { // Temperature is encoded without the signed bit, so clamp any negative temperatures to 0. temp = Math.max(0, temp); Loading Loading @@ -12421,6 +12423,8 @@ public class BatteryStatsImpl extends BatteryStats { mMinLearnedBatteryCapacity = Math.min(mMinLearnedBatteryCapacity, chargeFullUAh); } mMaxLearnedBatteryCapacity = Math.max(mMaxLearnedBatteryCapacity, chargeFullUAh); mBatteryTimeToFullSeconds = chargeTimeToFullSeconds; } public static boolean isOnBattery(int plugType, int status) { Loading Loading @@ -12570,19 +12574,10 @@ public class BatteryStatsImpl extends BatteryStats { // Not yet working. return -1; } /* Broken int curLevel = mCurrentBatteryLevel; int plugLevel = mDischargePlugLevel; if (plugLevel < 0 || curLevel < (plugLevel+1)) { return -1; if (mBatteryTimeToFullSeconds >= 0) { return mBatteryTimeToFullSeconds * (1000 * 1000); // s to us } long duration = computeBatteryRealtime(curTime, STATS_SINCE_UNPLUGGED); if (duration < 1000*1000) { return -1; } long usPerLevel = duration/(curLevel-plugLevel); return usPerLevel * (100-curLevel); */ // Else use algorithmic approach if (mChargeStepTracker.mNumStepDurations < 1) { return -1; } Loading services/core/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ java_library_static { "android.hardware.broadcastradio-V2.0-java", "android.hardware.health-V1.0-java", "android.hardware.health-V2.0-java", "android.hardware.health-V2.1-java", "android.hardware.light-java", "android.hardware.weaver-V1.0-java", "android.hardware.biometrics.face-V1.0-java", Loading services/core/java/com/android/server/BatteryService.java +28 −7 Original line number Diff line number Diff line Loading @@ -26,8 +26,10 @@ import android.content.Intent; import android.database.ContentObserver; import android.hardware.health.V1_0.HealthInfo; import android.hardware.health.V2_0.IHealth; import android.hardware.health.V2_0.IHealthInfoCallback; import android.hardware.health.V2_0.Result; import android.hardware.health.V2_1.BatteryCapacityLevel; import android.hardware.health.V2_1.Constants; import android.hardware.health.V2_1.IHealthInfoCallback; import android.hidl.manager.V1_0.IServiceManager; import android.hidl.manager.V1_0.IServiceNotification; import android.metrics.LogMaker; Loading Loading @@ -144,6 +146,7 @@ public final class BatteryService extends SystemService { private HealthInfo mHealthInfo; private final HealthInfo mLastHealthInfo = new HealthInfo(); private android.hardware.health.V2_1.HealthInfo mHealthInfo2p1; private boolean mBatteryLevelCritical; private int mLastBatteryStatus; private int mLastBatteryHealth; Loading Loading @@ -358,6 +361,9 @@ public final class BatteryService extends SystemService { } private boolean shouldShutdownLocked() { if (mHealthInfo2p1.batteryCapacityLevel != BatteryCapacityLevel.UNSUPPORTED) { return (mHealthInfo2p1.batteryCapacityLevel == BatteryCapacityLevel.CRITICAL); } if (mHealthInfo.batteryLevel > 0) { return false; } Loading Loading @@ -415,22 +421,23 @@ public final class BatteryService extends SystemService { } } private void update(android.hardware.health.V2_0.HealthInfo info) { private void update(android.hardware.health.V2_1.HealthInfo info) { traceBegin("HealthInfoUpdate"); Trace.traceCounter(Trace.TRACE_TAG_POWER, "BatteryChargeCounter", info.legacy.batteryChargeCounter); info.legacy.legacy.batteryChargeCounter); Trace.traceCounter(Trace.TRACE_TAG_POWER, "BatteryCurrent", info.legacy.batteryCurrent); info.legacy.legacy.batteryCurrent); synchronized (mLock) { if (!mUpdatesStopped) { mHealthInfo = info.legacy; mHealthInfo = info.legacy.legacy; mHealthInfo2p1 = info; // Process the new values. processValuesLocked(false); mLock.notifyAll(); // for any waiters on new info } else { copy(mLastHealthInfo, info.legacy); copy(mLastHealthInfo, info.legacy.legacy); } } traceEnd(); Loading Loading @@ -484,7 +491,8 @@ public final class BatteryService extends SystemService { mBatteryStats.setBatteryState(mHealthInfo.batteryStatus, mHealthInfo.batteryHealth, mPlugType, mHealthInfo.batteryLevel, mHealthInfo.batteryTemperature, mHealthInfo.batteryVoltage, mHealthInfo.batteryChargeCounter, mHealthInfo.batteryFullCharge); mHealthInfo.batteryFullCharge, mHealthInfo2p1.batteryChargeTimeToFullNowSeconds); } catch (RemoteException e) { // Should never happen. } Loading Loading @@ -1120,8 +1128,21 @@ public final class BatteryService extends SystemService { private final class HealthHalCallback extends IHealthInfoCallback.Stub implements HealthServiceWrapper.Callback { @Override public void healthInfoChanged(android.hardware.health.V2_0.HealthInfo props) { android.hardware.health.V2_1.HealthInfo propsLatest = new android.hardware.health.V2_1.HealthInfo(); propsLatest.legacy = props; propsLatest.batteryCapacityLevel = BatteryCapacityLevel.UNSUPPORTED; propsLatest.batteryChargeTimeToFullNowSeconds = Constants.BATTERY_CHARGE_TIME_TO_FULL_NOW_SECONDS_UNSUPPORTED; BatteryService.this.update(propsLatest); } @Override public void healthInfoChanged_2_1(android.hardware.health.V2_1.HealthInfo props) { BatteryService.this.update(props); } // on new service registered @Override public void onRegistration(IHealth oldService, IHealth newService, String instance) { Loading services/core/java/com/android/server/am/BatteryStatsService.java +3 −3 Original line number Diff line number Diff line Loading @@ -1133,7 +1133,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub @Override public void setBatteryState(final int status, final int health, final int plugType, final int level, final int temp, final int volt, final int chargeUAh, final int chargeFullUAh) { final int chargeFullUAh, final long chargeTimeToFullSeconds) { enforceCallingPermission(); // BatteryService calls us here and we may update external state. It would be wrong Loading @@ -1145,7 +1145,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub // The battery state has not changed, so we don't need to sync external // stats immediately. mStats.setBatteryStateLocked(status, health, plugType, level, temp, volt, chargeUAh, chargeFullUAh); chargeUAh, chargeFullUAh, chargeTimeToFullSeconds); return; } } Loading @@ -1158,7 +1158,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub mWorker.scheduleRunnable(() -> { synchronized (mStats) { mStats.setBatteryStateLocked(status, health, plugType, level, temp, volt, chargeUAh, chargeFullUAh); chargeUAh, chargeFullUAh, chargeTimeToFullSeconds); } }); }); Loading Loading
core/java/com/android/internal/app/IBatteryStats.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -133,7 +133,7 @@ interface IBatteryStats { void noteNetworkStatsEnabled(); void noteDeviceIdleMode(int mode, String activeReason, int activeUid); void setBatteryState(int status, int health, int plugType, int level, int temp, int volt, int chargeUAh, int chargeFullUAh); int chargeUAh, int chargeFullUAh, long chargeTimeToFullSeconds); @UnsupportedAppUsage long getAwakeTimeBattery(); long getAwakeTimePlugged(); Loading
core/java/com/android/internal/os/BatteryStatsImpl.java +9 −14 Original line number Diff line number Diff line Loading @@ -996,6 +996,8 @@ public class BatteryStatsImpl extends BatteryStats { private int mMinLearnedBatteryCapacity = -1; private int mMaxLearnedBatteryCapacity = -1; private long mBatteryTimeToFullSeconds = -1; private long[] mCpuFreqs; @VisibleForTesting Loading Loading @@ -12218,7 +12220,7 @@ public class BatteryStatsImpl extends BatteryStats { @GuardedBy("this") public void setBatteryStateLocked(final int status, final int health, final int plugType, final int level, /* not final */ int temp, final int volt, final int chargeUAh, final int chargeFullUAh) { final int chargeFullUAh, final long chargeTimeToFullSeconds) { // Temperature is encoded without the signed bit, so clamp any negative temperatures to 0. temp = Math.max(0, temp); Loading Loading @@ -12421,6 +12423,8 @@ public class BatteryStatsImpl extends BatteryStats { mMinLearnedBatteryCapacity = Math.min(mMinLearnedBatteryCapacity, chargeFullUAh); } mMaxLearnedBatteryCapacity = Math.max(mMaxLearnedBatteryCapacity, chargeFullUAh); mBatteryTimeToFullSeconds = chargeTimeToFullSeconds; } public static boolean isOnBattery(int plugType, int status) { Loading Loading @@ -12570,19 +12574,10 @@ public class BatteryStatsImpl extends BatteryStats { // Not yet working. return -1; } /* Broken int curLevel = mCurrentBatteryLevel; int plugLevel = mDischargePlugLevel; if (plugLevel < 0 || curLevel < (plugLevel+1)) { return -1; if (mBatteryTimeToFullSeconds >= 0) { return mBatteryTimeToFullSeconds * (1000 * 1000); // s to us } long duration = computeBatteryRealtime(curTime, STATS_SINCE_UNPLUGGED); if (duration < 1000*1000) { return -1; } long usPerLevel = duration/(curLevel-plugLevel); return usPerLevel * (100-curLevel); */ // Else use algorithmic approach if (mChargeStepTracker.mNumStepDurations < 1) { return -1; } Loading
services/core/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ java_library_static { "android.hardware.broadcastradio-V2.0-java", "android.hardware.health-V1.0-java", "android.hardware.health-V2.0-java", "android.hardware.health-V2.1-java", "android.hardware.light-java", "android.hardware.weaver-V1.0-java", "android.hardware.biometrics.face-V1.0-java", Loading
services/core/java/com/android/server/BatteryService.java +28 −7 Original line number Diff line number Diff line Loading @@ -26,8 +26,10 @@ import android.content.Intent; import android.database.ContentObserver; import android.hardware.health.V1_0.HealthInfo; import android.hardware.health.V2_0.IHealth; import android.hardware.health.V2_0.IHealthInfoCallback; import android.hardware.health.V2_0.Result; import android.hardware.health.V2_1.BatteryCapacityLevel; import android.hardware.health.V2_1.Constants; import android.hardware.health.V2_1.IHealthInfoCallback; import android.hidl.manager.V1_0.IServiceManager; import android.hidl.manager.V1_0.IServiceNotification; import android.metrics.LogMaker; Loading Loading @@ -144,6 +146,7 @@ public final class BatteryService extends SystemService { private HealthInfo mHealthInfo; private final HealthInfo mLastHealthInfo = new HealthInfo(); private android.hardware.health.V2_1.HealthInfo mHealthInfo2p1; private boolean mBatteryLevelCritical; private int mLastBatteryStatus; private int mLastBatteryHealth; Loading Loading @@ -358,6 +361,9 @@ public final class BatteryService extends SystemService { } private boolean shouldShutdownLocked() { if (mHealthInfo2p1.batteryCapacityLevel != BatteryCapacityLevel.UNSUPPORTED) { return (mHealthInfo2p1.batteryCapacityLevel == BatteryCapacityLevel.CRITICAL); } if (mHealthInfo.batteryLevel > 0) { return false; } Loading Loading @@ -415,22 +421,23 @@ public final class BatteryService extends SystemService { } } private void update(android.hardware.health.V2_0.HealthInfo info) { private void update(android.hardware.health.V2_1.HealthInfo info) { traceBegin("HealthInfoUpdate"); Trace.traceCounter(Trace.TRACE_TAG_POWER, "BatteryChargeCounter", info.legacy.batteryChargeCounter); info.legacy.legacy.batteryChargeCounter); Trace.traceCounter(Trace.TRACE_TAG_POWER, "BatteryCurrent", info.legacy.batteryCurrent); info.legacy.legacy.batteryCurrent); synchronized (mLock) { if (!mUpdatesStopped) { mHealthInfo = info.legacy; mHealthInfo = info.legacy.legacy; mHealthInfo2p1 = info; // Process the new values. processValuesLocked(false); mLock.notifyAll(); // for any waiters on new info } else { copy(mLastHealthInfo, info.legacy); copy(mLastHealthInfo, info.legacy.legacy); } } traceEnd(); Loading Loading @@ -484,7 +491,8 @@ public final class BatteryService extends SystemService { mBatteryStats.setBatteryState(mHealthInfo.batteryStatus, mHealthInfo.batteryHealth, mPlugType, mHealthInfo.batteryLevel, mHealthInfo.batteryTemperature, mHealthInfo.batteryVoltage, mHealthInfo.batteryChargeCounter, mHealthInfo.batteryFullCharge); mHealthInfo.batteryFullCharge, mHealthInfo2p1.batteryChargeTimeToFullNowSeconds); } catch (RemoteException e) { // Should never happen. } Loading Loading @@ -1120,8 +1128,21 @@ public final class BatteryService extends SystemService { private final class HealthHalCallback extends IHealthInfoCallback.Stub implements HealthServiceWrapper.Callback { @Override public void healthInfoChanged(android.hardware.health.V2_0.HealthInfo props) { android.hardware.health.V2_1.HealthInfo propsLatest = new android.hardware.health.V2_1.HealthInfo(); propsLatest.legacy = props; propsLatest.batteryCapacityLevel = BatteryCapacityLevel.UNSUPPORTED; propsLatest.batteryChargeTimeToFullNowSeconds = Constants.BATTERY_CHARGE_TIME_TO_FULL_NOW_SECONDS_UNSUPPORTED; BatteryService.this.update(propsLatest); } @Override public void healthInfoChanged_2_1(android.hardware.health.V2_1.HealthInfo props) { BatteryService.this.update(props); } // on new service registered @Override public void onRegistration(IHealth oldService, IHealth newService, String instance) { Loading
services/core/java/com/android/server/am/BatteryStatsService.java +3 −3 Original line number Diff line number Diff line Loading @@ -1133,7 +1133,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub @Override public void setBatteryState(final int status, final int health, final int plugType, final int level, final int temp, final int volt, final int chargeUAh, final int chargeFullUAh) { final int chargeFullUAh, final long chargeTimeToFullSeconds) { enforceCallingPermission(); // BatteryService calls us here and we may update external state. It would be wrong Loading @@ -1145,7 +1145,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub // The battery state has not changed, so we don't need to sync external // stats immediately. mStats.setBatteryStateLocked(status, health, plugType, level, temp, volt, chargeUAh, chargeFullUAh); chargeUAh, chargeFullUAh, chargeTimeToFullSeconds); return; } } Loading @@ -1158,7 +1158,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub mWorker.scheduleRunnable(() -> { synchronized (mStats) { mStats.setBatteryStateLocked(status, health, plugType, level, temp, volt, chargeUAh, chargeFullUAh); chargeUAh, chargeFullUAh, chargeTimeToFullSeconds); } }); }); Loading