diff options
author | Adam Lesinski <adamlesinski@google.com> | 2015-03-02 13:06:46 -0800 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2015-03-02 13:06:46 -0800 |
commit | 3a0831bfe6e69a2ad11b9f6fae04fb27daa40a88 (patch) | |
tree | 71b2b5a5a7e503b85c6e020caeaa5b2712c0dcdc /services/usage/java/com/android/server | |
parent | 978a1ed5aa2752cd36ff51df91d2d2d8be2171d9 (diff) | |
download | frameworks_base-3a0831bfe6e69a2ad11b9f6fae04fb27daa40a88.zip frameworks_base-3a0831bfe6e69a2ad11b9f6fae04fb27daa40a88.tar.gz frameworks_base-3a0831bfe6e69a2ad11b9f6fae04fb27daa40a88.tar.bz2 |
Fix issue where pruned UsageStats files would not be removed from index
This would cause an exception to be thrown when querying stats
that included a deleted file and cause only in-memory stats to be
returned.
This change now re-indexes after deleting files.
Furthermore, we continue reading UsageStats files in order
to return more useful data if some other issue (file corruption)
leads us to fail reading a file.
Change-Id: I4a52739624d68e719e3d7d324a0b16709a62ac7a
Diffstat (limited to 'services/usage/java/com/android/server')
-rw-r--r-- | services/usage/java/com/android/server/usage/UsageStatsDatabase.java | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/services/usage/java/com/android/server/usage/UsageStatsDatabase.java b/services/usage/java/com/android/server/usage/UsageStatsDatabase.java index 26ced03..235567c 100644 --- a/services/usage/java/com/android/server/usage/UsageStatsDatabase.java +++ b/services/usage/java/com/android/server/usage/UsageStatsDatabase.java @@ -378,26 +378,27 @@ class UsageStatsDatabase { } } - try { - IntervalStats stats = new IntervalStats(); - ArrayList<T> results = new ArrayList<>(); - for (int i = startIndex; i <= endIndex; i++) { - final AtomicFile f = intervalStats.valueAt(i); + final IntervalStats stats = new IntervalStats(); + final ArrayList<T> results = new ArrayList<>(); + for (int i = startIndex; i <= endIndex; i++) { + final AtomicFile f = intervalStats.valueAt(i); - if (DEBUG) { - Slog.d(TAG, "Reading stat file " + f.getBaseFile().getAbsolutePath()); - } + if (DEBUG) { + Slog.d(TAG, "Reading stat file " + f.getBaseFile().getAbsolutePath()); + } + try { UsageStatsXml.read(f, stats); if (beginTime < stats.endTime) { combiner.combine(stats, false, results); } + } catch (IOException e) { + Slog.e(TAG, "Failed to read usage stats file", e); + // We continue so that we return results that are not + // corrupt. } - return results; - } catch (IOException e) { - Slog.e(TAG, "Failed to read usage stats file", e); - return null; } + return results; } } @@ -450,6 +451,10 @@ class UsageStatsDatabase { mCal.addDays(-7); pruneFilesOlderThan(mIntervalDirs[UsageStatsManager.INTERVAL_DAILY], mCal.getTimeInMillis()); + + // We must re-index our file list or we will be trying to read + // deleted files. + indexFilesLocked(); } } |