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

Commit c00fb2ef authored by YK Hung's avatar YK Hung Committed by Android (Google) Code Review
Browse files

Merge "Optimize screen time cross power connection logic from O(N^2) to O(N)" into udc-dev

parents 65136fa9 680cd305
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()