am 05f5cb45: Merge "UsageStats: Gracefully handle corrupt filenames" into mnc-dev
* commit '05f5cb45997fdc8831798bb84e50854cdfab2bcb': UsageStats: Gracefully handle corrupt filenames
This commit is contained in:
@@ -191,7 +191,11 @@ class UsageStatsDatabase {
|
|||||||
|
|
||||||
for (File f : files) {
|
for (File f : files) {
|
||||||
final AtomicFile af = new AtomicFile(f);
|
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)) {
|
if (path.endsWith(BAK_SUFFIX)) {
|
||||||
f = new File(path.substring(0, path.length() - BAK_SUFFIX.length()));
|
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) {
|
if (beginTime < expiryTime) {
|
||||||
new AtomicFile(f).delete();
|
new AtomicFile(f).delete();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,11 +33,11 @@ public class UsageStatsXml {
|
|||||||
private static final String VERSION_ATTR = "version";
|
private static final String VERSION_ATTR = "version";
|
||||||
static final String CHECKED_IN_SUFFIX = "-c";
|
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());
|
return parseBeginTime(file.getBaseFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long parseBeginTime(File file) {
|
public static long parseBeginTime(File file) throws IOException {
|
||||||
String name = file.getName();
|
String name = file.getName();
|
||||||
|
|
||||||
// Eat as many occurrences of -c as possible. This is due to a bug where -c
|
// 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)) {
|
while (name.endsWith(CHECKED_IN_SUFFIX)) {
|
||||||
name = name.substring(0, name.length() - CHECKED_IN_SUFFIX.length());
|
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 {
|
public static void read(AtomicFile file, IntervalStats statsOut) throws IOException {
|
||||||
|
|||||||
Reference in New Issue
Block a user