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

Commit 5f28beac authored by jackqdyulei's avatar jackqdyulei
Browse files

Report High usage even in a short period

In detector, we should also catch the following case:
1. Battery draining more than 25% even though usage time is less than
2 hours.

This cl stores the first time battery level, even though usage time
may be short.

Bug: 73012441
Test: RunSettingsRoboTests
Change-Id: I7106f7203718bfe2afe9cce297ea01b8fcf0be2d
parent c07124fe
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ public class HighUsageDataParser implements BatteryInfo.BatteryDataParser {

    @Override
    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
            // closet battery level 'mTimePeriodMs' time ago.
            mLastPeriodBatteryLevel = record.batteryLevel;
+11 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import java.time.Duration;
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class HighUsageDataParserTest {
    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 int THRESHOLD_LOW = 10;
    private static final int THRESHOLD_HIGH = 20;
@@ -75,7 +76,17 @@ public class HighUsageDataParserTest {
        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() {
        // Report the battery usage in END_TIME_MS(2 minutes)
        mDataParser.onParsingStarted(0, END_TIME_MS);
        mDataParser.onDataPoint(0, mFirstItem);
        mDataParser.onDataPoint(PERIOD_ONE_MINUTE_MS, mSecondItem);