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

Commit d89e9c2e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Report High usage even in a short period"

parents c3bc3bc6 5f28beac
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -51,7 +51,7 @@ public class HighUsageDataParser implements BatteryInfo.BatteryDataParser {


    @Override
    @Override
    public void onDataPoint(long time, BatteryStats.HistoryItem record) {
    public void onDataPoint(long time, BatteryStats.HistoryItem record) {
        if (record.currentTime <= mEndTimeMs - mTimePeriodMs) {
        if (time == 0 || record.currentTime <= mEndTimeMs - mTimePeriodMs) {
            // Since onDataPoint is invoked sorted by time, so we could use this way to get the
            // Since onDataPoint is invoked sorted by time, so we could use this way to get the
            // closet battery level 'mTimePeriodMs' time ago.
            // closet battery level 'mTimePeriodMs' time ago.
            mLastPeriodBatteryLevel = record.batteryLevel;
            mLastPeriodBatteryLevel = record.batteryLevel;
+11 −0
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@ import java.time.Duration;
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class HighUsageDataParserTest {
public class HighUsageDataParserTest {
    private static final long PERIOD_ONE_MINUTE_MS = Duration.ofMinutes(1).toMillis();
    private static final long PERIOD_ONE_MINUTE_MS = Duration.ofMinutes(1).toMillis();
    private static final long PERIOD_ONE_HOUR_MS = Duration.ofHours(1).toMillis();
    private static final long END_TIME_MS = 2 * PERIOD_ONE_MINUTE_MS;
    private static final long END_TIME_MS = 2 * PERIOD_ONE_MINUTE_MS;
    private static final int THRESHOLD_LOW = 10;
    private static final int THRESHOLD_LOW = 10;
    private static final int THRESHOLD_HIGH = 20;
    private static final int THRESHOLD_HIGH = 20;
@@ -75,7 +76,17 @@ public class HighUsageDataParserTest {
        assertThat(mDataParser.isDeviceHeavilyUsed()).isFalse();
        assertThat(mDataParser.isDeviceHeavilyUsed()).isFalse();
    }
    }


    @Test
    public void testDataParser_heavilyUsedInShortTime_stillReportHeavilyUsed() {
        // Set threshold to 1 hour however device only used for 2 minutes
        mDataParser = new HighUsageDataParser(PERIOD_ONE_HOUR_MS, THRESHOLD_LOW);
        parseData();

        assertThat(mDataParser.isDeviceHeavilyUsed()).isTrue();
    }

    private void parseData() {
    private void parseData() {
        // Report the battery usage in END_TIME_MS(2 minutes)
        mDataParser.onParsingStarted(0, END_TIME_MS);
        mDataParser.onParsingStarted(0, END_TIME_MS);
        mDataParser.onDataPoint(0, mFirstItem);
        mDataParser.onDataPoint(0, mFirstItem);
        mDataParser.onDataPoint(PERIOD_ONE_MINUTE_MS, mSecondItem);
        mDataParser.onDataPoint(PERIOD_ONE_MINUTE_MS, mSecondItem);