Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 965cd8a2 authored by Sam McNally's avatar Sam McNally
Browse files

Implement the BATTERY_LIFE pulled atom.

Implement it alongside other pulled atoms surfacing data from health
HAL. The calculation estimates battery life using the battery-reported
full capacity and current, scaling to report in minutes and discard 4%
as an estimate for early shutdown before the battery fully discharges.

Flag: EXEMPT statsd atoms/metrics changes
Bug: 419415594
Test: statsd_testdrive 10245
Change-Id: If2d6bcbd5829fa37ac43b1c732e3399d45c8b623
parent c018324a
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -810,6 +810,7 @@ public class StatsPullAtomService extends SystemService {
                    case FrameworkStatsLog.BATTERY_VOLTAGE:
                    case FrameworkStatsLog.BATTERY_CYCLE_COUNT:
                    case FrameworkStatsLog.BATTERY_HEALTH:
                    case FrameworkStatsLog.BATTERY_LIFE:
                        synchronized (mHealthHalLock) {
                            return pullHealthHalLocked(atomTag, data);
                        }
@@ -1068,6 +1069,7 @@ public class StatsPullAtomService extends SystemService {
        if (ENABLE_PRESSURE_STALL_INFORMATION_PULLER) {
            registerPressureStallInformation();
        }
        registerBatteryLife();
    }

    private void initMobileDataStatsPuller() {
@@ -4433,6 +4435,13 @@ public class StatsPullAtomService extends SystemService {
                DIRECT_EXECUTOR, mStatsCallbackImpl);
    }

    private void registerBatteryLife() {
        int tagId = FrameworkStatsLog.BATTERY_LIFE;
        mStatsManager.setPullAtomCallback(tagId,
                null, // use default PullAtomMetadata values
                DIRECT_EXECUTOR, mStatsCallbackImpl);
    }

    @GuardedBy("mHealthHalLock")
    private int pullHealthHalLocked(int atomTag, List<StatsEvent> pulledData) {
        if (mHealthService == null) {
@@ -4503,6 +4512,13 @@ public class StatsPullAtomService extends SystemService {
                    Slog.e(TAG, "Could not find message digest algorithm", e);
                }
                return StatsManager.PULL_SKIP;
            case FrameworkStatsLog.BATTERY_LIFE:
                if (!healthInfo.batteryPresent || healthInfo.batteryCurrentMicroamps == 0) {
                    return StatsManager.PULL_SKIP;
                }
                pulledValue = (int) Math.round(((double) healthInfo.batteryFullChargeUah * 60 * .96)
                    / Math.abs(healthInfo.batteryCurrentMicroamps));
                break;
            default:
                return StatsManager.PULL_SKIP;
        }