Add wipeOnError flag to NetworkStatsRecorder
If reading data happens exception while doing data migration, the file will be deleted by legacy recorders. This would cause legacy persistent data being lost and cannot be retrieved by any method. To avoid the files being deleted, add a wipeOnError flag to recorder which indicates this recorder will wipe on error or not . If the flag is set to true then deletes all files when it throws, otherwise keeps all files. (cherry-picked from ag/18910973) Bug: 233828210 Test: FrameworksNetTests:NetworkStatsRecorderTest Change-Id: Id7a3d8bebf8a00d814f9e84bf4c10d927e6ff749 Merged-In: Id7a3d8bebf8a00d814f9e84bf4c10d927e6ff749
This commit is contained in:
@@ -2025,18 +2025,18 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
||||
}
|
||||
|
||||
private NetworkStatsRecorder makeTestRecorder(File directory, String prefix, Config config,
|
||||
boolean includeTags) {
|
||||
boolean includeTags, boolean wipeOnError) {
|
||||
final NetworkStats.NonMonotonicObserver observer =
|
||||
mock(NetworkStats.NonMonotonicObserver.class);
|
||||
final DropBoxManager dropBox = mock(DropBoxManager.class);
|
||||
return new NetworkStatsRecorder(new FileRotator(
|
||||
directory, prefix, config.rotateAgeMillis, config.deleteAgeMillis),
|
||||
observer, dropBox, prefix, config.bucketDuration, includeTags);
|
||||
observer, dropBox, prefix, config.bucketDuration, includeTags, wipeOnError);
|
||||
}
|
||||
|
||||
private NetworkStatsCollection getLegacyCollection(String prefix, boolean includeTags) {
|
||||
final NetworkStatsRecorder recorder = makeTestRecorder(mLegacyStatsDir, prefix,
|
||||
mSettings.getDevConfig(), includeTags);
|
||||
mSettings.getDevConfig(), includeTags, false);
|
||||
return recorder.getOrLoadCompleteLocked();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user