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 @@ -1000,6 +1000,8 @@ public class BatteryStatsImpl extends BatteryStats { private int mMinLearnedBatteryCapacity = -1; private int mMaxLearnedBatteryCapacity = -1; private long mBatteryTimeToFullSeconds = -1; private long[] mCpuFreqs; @VisibleForTesting Loading Loading @@ -12226,7 +12228,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 @@ -12429,6 +12431,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 @@ -12578,19 +12582,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 @@ -113,6 +113,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.1-java", Loading services/core/java/com/android/server/BatteryService.java +28 −7 Original line number Diff line number Diff line Loading @@ -27,8 +27,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 @@ -145,6 +147,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 @@ -359,6 +362,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 @@ -416,22 +422,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 @@ -485,7 +492,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 @@ -1123,8 +1131,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 @@ -1135,7 +1135,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 @@ -1147,7 +1147,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 @@ -1160,7 +1160,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 @@ -1000,6 +1000,8 @@ public class BatteryStatsImpl extends BatteryStats { private int mMinLearnedBatteryCapacity = -1; private int mMaxLearnedBatteryCapacity = -1; private long mBatteryTimeToFullSeconds = -1; private long[] mCpuFreqs; @VisibleForTesting Loading Loading @@ -12226,7 +12228,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 @@ -12429,6 +12431,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 @@ -12578,19 +12582,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 @@ -113,6 +113,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.1-java", Loading
services/core/java/com/android/server/BatteryService.java +28 −7 Original line number Diff line number Diff line Loading @@ -27,8 +27,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 @@ -145,6 +147,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 @@ -359,6 +362,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 @@ -416,22 +422,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 @@ -485,7 +492,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 @@ -1123,8 +1131,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 @@ -1135,7 +1135,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 @@ -1147,7 +1147,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 @@ -1160,7 +1160,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