Loading services/usage/java/com/android/server/usage/UsageStatsDatabase.java +21 −20 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.usage; import android.annotation.Nullable; import android.app.usage.TimeSparseArray; import android.app.usage.UsageEvents; import android.app.usage.UsageStats; Loading Loading @@ -788,7 +789,7 @@ public class UsageStatsDatabase { public interface StatCombiner<T> { /** * Implementations should extract interesting from <code>stats</code> and add it * Implementations should extract interesting information from <code>stats</code> and add it * to the <code>accumulatedResult</code> list. * * If the <code>stats</code> object is mutable, <code>mutable</code> will be true, Loading @@ -805,15 +806,14 @@ public class UsageStatsDatabase { /** * Find all {@link IntervalStats} for the given range and interval type. */ @Nullable public <T> List<T> queryUsageStats(int intervalType, long beginTime, long endTime, StatCombiner<T> combiner) { synchronized (mLock) { // mIntervalDirs is final. Accessing its size without holding the lock should be fine. if (intervalType < 0 || intervalType >= mIntervalDirs.length) { throw new IllegalArgumentException("Bad interval type " + intervalType); } final TimeSparseArray<AtomicFile> intervalStats = mSortedStatFiles[intervalType]; if (endTime <= beginTime) { if (DEBUG) { Slog.d(TAG, "endTime(" + endTime + ") <= beginTime(" + beginTime + ")"); Loading @@ -821,12 +821,8 @@ public class UsageStatsDatabase { return null; } int startIndex = intervalStats.closestIndexOnOrBefore(beginTime); if (startIndex < 0) { // All the stats available have timestamps after beginTime, which means they all // match. startIndex = 0; } synchronized (mLock) { final TimeSparseArray<AtomicFile> intervalStats = mSortedStatFiles[intervalType]; int endIndex = intervalStats.closestIndexOnOrBefore(endTime); if (endIndex < 0) { Loading @@ -849,6 +845,13 @@ public class UsageStatsDatabase { } } int startIndex = intervalStats.closestIndexOnOrBefore(beginTime); if (startIndex < 0) { // All the stats available have timestamps after beginTime, which means they all // match. startIndex = 0; } final ArrayList<T> results = new ArrayList<>(); for (int i = startIndex; i <= endIndex; i++) { final AtomicFile f = intervalStats.valueAt(i); Loading Loading @@ -985,7 +988,6 @@ public class UsageStatsDatabase { } } private static long parseBeginTime(AtomicFile file) throws IOException { return parseBeginTime(file.getBaseFile()); } Loading Loading @@ -1233,7 +1235,6 @@ public class UsageStatsDatabase { } } /* Backup/Restore Code */ byte[] getBackupPayload(String key) { return getBackupPayload(key, BACKUP_VERSION); Loading Loading
services/usage/java/com/android/server/usage/UsageStatsDatabase.java +21 −20 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.usage; import android.annotation.Nullable; import android.app.usage.TimeSparseArray; import android.app.usage.UsageEvents; import android.app.usage.UsageStats; Loading Loading @@ -788,7 +789,7 @@ public class UsageStatsDatabase { public interface StatCombiner<T> { /** * Implementations should extract interesting from <code>stats</code> and add it * Implementations should extract interesting information from <code>stats</code> and add it * to the <code>accumulatedResult</code> list. * * If the <code>stats</code> object is mutable, <code>mutable</code> will be true, Loading @@ -805,15 +806,14 @@ public class UsageStatsDatabase { /** * Find all {@link IntervalStats} for the given range and interval type. */ @Nullable public <T> List<T> queryUsageStats(int intervalType, long beginTime, long endTime, StatCombiner<T> combiner) { synchronized (mLock) { // mIntervalDirs is final. Accessing its size without holding the lock should be fine. if (intervalType < 0 || intervalType >= mIntervalDirs.length) { throw new IllegalArgumentException("Bad interval type " + intervalType); } final TimeSparseArray<AtomicFile> intervalStats = mSortedStatFiles[intervalType]; if (endTime <= beginTime) { if (DEBUG) { Slog.d(TAG, "endTime(" + endTime + ") <= beginTime(" + beginTime + ")"); Loading @@ -821,12 +821,8 @@ public class UsageStatsDatabase { return null; } int startIndex = intervalStats.closestIndexOnOrBefore(beginTime); if (startIndex < 0) { // All the stats available have timestamps after beginTime, which means they all // match. startIndex = 0; } synchronized (mLock) { final TimeSparseArray<AtomicFile> intervalStats = mSortedStatFiles[intervalType]; int endIndex = intervalStats.closestIndexOnOrBefore(endTime); if (endIndex < 0) { Loading @@ -849,6 +845,13 @@ public class UsageStatsDatabase { } } int startIndex = intervalStats.closestIndexOnOrBefore(beginTime); if (startIndex < 0) { // All the stats available have timestamps after beginTime, which means they all // match. startIndex = 0; } final ArrayList<T> results = new ArrayList<>(); for (int i = startIndex; i <= endIndex; i++) { final AtomicFile f = intervalStats.valueAt(i); Loading Loading @@ -985,7 +988,6 @@ public class UsageStatsDatabase { } } private static long parseBeginTime(AtomicFile file) throws IOException { return parseBeginTime(file.getBaseFile()); } Loading Loading @@ -1233,7 +1235,6 @@ public class UsageStatsDatabase { } } /* Backup/Restore Code */ byte[] getBackupPayload(String key) { return getBackupPayload(key, BACKUP_VERSION); Loading