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

Commit bfbe71e1 authored by Michael Wachenschwanz's avatar Michael Wachenschwanz
Browse files

Minor fixes to IntervalStats

Close hole in IntervalStats time tracking.
Fix EventTracker commitTime math
Also make eventList final

Fixes: 124850206
Test: builds and runs

Change-Id: I967cd4b3f5ccea0f7f8fd7e8729f258a5f8f1981
parent 66b5c276
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -103,4 +103,18 @@ public class EventList {
        }
        return result;
    }

    /**
     * Merge the {@link UsageEvents.Event events} in the given {@link EventList list} into this
     * list while keeping the list sorted based on the event {@link
     * UsageEvents.Event#mTimeStamp timestamps}.
     *
     * @param events The event list to merge
     */
    public void merge(EventList events) {
        final int size = events.size();
        for (int i = 0; i < size; i++) {
            insert(events.get(i));
        }
    }
}
+11 −5
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ public class IntervalStats {
    public final ArrayMap<String, UsageStats> packageStats = new ArrayMap<>();
    public final ArrayMap<Configuration, ConfigurationStats> configurations = new ArrayMap<>();
    public Configuration activeConfiguration;
    public EventList events = new EventList();
    public final EventList events = new EventList();

    // A string cache. This is important as when we're parsing XML files, we don't want to
    // keep hundreds of strings that have the same contents. We will read the string
@@ -82,7 +82,7 @@ public class IntervalStats {

        public void commitTime(long timeStamp) {
            if (curStartTime != 0) {
                duration += timeStamp - duration;
                duration += timeStamp - curStartTime;
                curStartTime = 0;
            }
        }
@@ -305,8 +305,10 @@ public class IntervalStats {
            UsageStats usageStats = getOrCreateUsageStats(packageName);
            usageStats.update(className, timeStamp, eventType, instanceId);
        }
        if (timeStamp > endTime) {
            endTime = timeStamp;
        }
    }

    /**
     * @hide
@@ -328,6 +330,9 @@ public class IntervalStats {
            event.mNotificationChannelId = getCachedStringRef(event.mNotificationChannelId);
        }
        events.insert(event);
        if (event.mTimeStamp > endTime) {
            endTime = event.mTimeStamp;
        }
    }

    void updateChooserCounts(String packageName, String category, String action) {
@@ -360,9 +365,10 @@ public class IntervalStats {
            configStats.mActivationCount += 1;
            activeConfiguration = configStats.mConfiguration;
        }

        if (timeStamp > endTime) {
            endTime = timeStamp;
        }
    }

    void incrementAppLaunchCount(String packageName) {
        UsageStats usageStats = getOrCreateUsageStats(packageName);
+2 −1
Original line number Diff line number Diff line
@@ -1166,7 +1166,8 @@ public class UsageStatsDatabase {
        if (beingRestored == null) return null;
        beingRestored.activeConfiguration = onDevice.activeConfiguration;
        beingRestored.configurations.putAll(onDevice.configurations);
        beingRestored.events = onDevice.events;
        beingRestored.events.clear();
        beingRestored.events.merge(onDevice.events);
        return beingRestored;
    }

+1 −1
Original line number Diff line number Diff line
@@ -334,7 +334,7 @@ class UserUsageStatsService {
                final IntervalStats diskStats = mDatabase.getLatestUsageStats(
                        INTERVAL_DAILY);
                StringBuilder sb = new StringBuilder(256);
                sb.append("Last 24 hours of UsageStats missing! timeRange : ");
                sb.append("Recent UsageStats missing! timeRange : ");
                sb.append(beginTime);
                sb.append(", ");
                sb.append(endTime);