summaryrefslogtreecommitdiffstats
path: root/services/usage
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2015-07-22 16:01:45 -0700
committerAdam Lesinski <adamlesinski@google.com>2015-07-22 16:01:45 -0700
commite03f17c82eac7b6ce55e434fab29c7c428b46baa (patch)
tree3671a00ba8f5409962d5a8840290cdd07fb12266 /services/usage
parent3d6f606031da248a3b1fd6f0f569ac33a26c0b5e (diff)
downloadframeworks_base-e03f17c82eac7b6ce55e434fab29c7c428b46baa.zip
frameworks_base-e03f17c82eac7b6ce55e434fab29c7c428b46baa.tar.gz
frameworks_base-e03f17c82eac7b6ce55e434fab29c7c428b46baa.tar.bz2
UsageStats: Gracefully handle corrupt filenames
Not sure how useful this is, since renames should be atomic. If the filesystem is corrupt I'm sure other parts of the system will break. Good to be safe though! Bug:22172659 Change-Id: Iad339be2869d170bcf736c59feb93830a51905e1
Diffstat (limited to 'services/usage')
-rw-r--r--services/usage/java/com/android/server/usage/UsageStatsDatabase.java15
-rw-r--r--services/usage/java/com/android/server/usage/UsageStatsXml.java11
2 files changed, 21 insertions, 5 deletions
diff --git a/services/usage/java/com/android/server/usage/UsageStatsDatabase.java b/services/usage/java/com/android/server/usage/UsageStatsDatabase.java
index 4498b84..0a7091e 100644
--- a/services/usage/java/com/android/server/usage/UsageStatsDatabase.java
+++ b/services/usage/java/com/android/server/usage/UsageStatsDatabase.java
@@ -191,7 +191,11 @@ class UsageStatsDatabase {
for (File f : files) {
final AtomicFile af = new AtomicFile(f);
- mSortedStatFiles[i].put(UsageStatsXml.parseBeginTime(af), af);
+ try {
+ mSortedStatFiles[i].put(UsageStatsXml.parseBeginTime(af), af);
+ } catch (IOException e) {
+ Slog.e(TAG, "failed to index file: " + f, e);
+ }
}
}
}
@@ -506,7 +510,14 @@ class UsageStatsDatabase {
if (path.endsWith(BAK_SUFFIX)) {
f = new File(path.substring(0, path.length() - BAK_SUFFIX.length()));
}
- long beginTime = UsageStatsXml.parseBeginTime(f);
+
+ long beginTime;
+ try {
+ beginTime = UsageStatsXml.parseBeginTime(f);
+ } catch (IOException e) {
+ beginTime = 0;
+ }
+
if (beginTime < expiryTime) {
new AtomicFile(f).delete();
}
diff --git a/services/usage/java/com/android/server/usage/UsageStatsXml.java b/services/usage/java/com/android/server/usage/UsageStatsXml.java
index 186813e..543f361 100644
--- a/services/usage/java/com/android/server/usage/UsageStatsXml.java
+++ b/services/usage/java/com/android/server/usage/UsageStatsXml.java
@@ -33,11 +33,11 @@ public class UsageStatsXml {
private static final String VERSION_ATTR = "version";
static final String CHECKED_IN_SUFFIX = "-c";
- public static long parseBeginTime(AtomicFile file) {
+ public static long parseBeginTime(AtomicFile file) throws IOException {
return parseBeginTime(file.getBaseFile());
}
- public static long parseBeginTime(File file) {
+ public static long parseBeginTime(File file) throws IOException {
String name = file.getName();
// Eat as many occurrences of -c as possible. This is due to a bug where -c
@@ -47,7 +47,12 @@ public class UsageStatsXml {
while (name.endsWith(CHECKED_IN_SUFFIX)) {
name = name.substring(0, name.length() - CHECKED_IN_SUFFIX.length());
}
- return Long.parseLong(name);
+
+ try {
+ return Long.parseLong(name);
+ } catch (NumberFormatException e) {
+ throw new IOException(e);
+ }
}
public static void read(AtomicFile file, IntervalStats statsOut) throws IOException {