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

Commit 680cd305 authored by Zaiyue Xue's avatar Zaiyue Xue
Browse files

Optimize screen time cross power connection logic from O(N^2) to O(N)

Bug: 277844625
Fix: 277844625
Test: presubmit
Change-Id: If945e45a5eb279fd730dcc13575dd4fe45ac3ad4
parent fbe85872
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -852,9 +852,11 @@ public final class DataProcessor {
            final List<AppUsagePeriod> usagePeriodList,
            final List<BatteryEvent> batteryEventList) {
        final List<AppUsagePeriod> resultList = new ArrayList<>();
        int index = 0;
        for (AppUsagePeriod inputPeriod : usagePeriodList) {
            long lastStartTime = inputPeriod.getStartTime();
            for (BatteryEvent batteryEvent : batteryEventList) {
            while (index < batteryEventList.size()) {
                BatteryEvent batteryEvent = batteryEventList.get(index);
                if (batteryEvent.getTimestamp() < inputPeriod.getStartTime()) {
                    // Because the batteryEventList has been sorted, here is to mark the power
                    // connection state when the usage period starts. If power is connected when
@@ -865,6 +867,7 @@ public final class DataProcessor {
                    } else if (batteryEvent.getType() == BatteryEventType.POWER_DISCONNECTED) {
                        lastStartTime = inputPeriod.getStartTime();
                    }
                    index++;
                    continue;
                }
                if (batteryEvent.getTimestamp() > inputPeriod.getEndTime()) {
@@ -883,6 +886,7 @@ public final class DataProcessor {
                } else if (batteryEvent.getType() == BatteryEventType.POWER_DISCONNECTED) {
                    lastStartTime = batteryEvent.getTimestamp();
                }
                index++;
            }
            if (lastStartTime != 0) {
                resultList.add(AppUsagePeriod.newBuilder()