Merge "Optimize screen time cross power connection logic from O(N^2) to O(N)" into udc-dev
This commit is contained in:
@@ -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()
|
||||
|
Reference in New Issue
Block a user