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

Commit 3ed19f26 authored by Vova Sharaienko's avatar Vova Sharaienko
Browse files

Updated StatsPerUidLogger device wide component power consumed reporting

- updated powerMah to float conversion

Flag: com.android.server.power.optimization.add_battery_usage_stats_slice_atom
Bug: 368271881
Test: atest android.cts.statsdatom.batterystats.BatteryUsageStatsTests#testBatteryUsageStatsPerUid
Change-Id: I8348940e0ea65c21a8019240043f77238c0a93c9
parent 3fede68d
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
@@ -1251,12 +1251,10 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        }

        private static float clampPowerMah(double powerMah, String consumer) {
            float resultPowerMah = 0;
            if (powerMah <= Float.MAX_VALUE && powerMah >= Float.MIN_VALUE) {
                resultPowerMah = (float) powerMah;
            } else {
                // Handle overflow appropriately
                Slog.wtfStack(TAG, consumer + " reported powerMah float overflow: " + powerMah);
            float resultPowerMah = Double.valueOf(powerMah).floatValue();
            if (Float.isInfinite(resultPowerMah)) {
                resultPowerMah = 0;
                Slog.d(TAG, consumer + " reported powerMah float overflow : " + powerMah);
            }
            return resultPowerMah;
        }
@@ -1361,11 +1359,10 @@ public final class BatteryStatsService extends IBatteryStats.Stub

            final String powerComponentName = batteryConsumer.getPowerComponentName(componentId);
            final double consumedPowerMah = batteryConsumer.getConsumedPower(key);
            float powerMah =
            final float powerMah =
                    clampPowerMah(
                            consumedPowerMah, "uidConsumer-" + uid + "-" + powerComponentName);
                            consumedPowerMah, "uid-" + uid + "-" + powerComponentName);
            final long powerComponentDurationMillis = batteryConsumer.getUsageDurationMillis(key);

            if (powerMah == 0 && powerComponentDurationMillis == 0) {
                return true;
            }