Merge "Fixed to prevent usagestats file corruption when writing"
This commit is contained in:
@@ -1025,6 +1025,8 @@ public class UsageStatsDatabase {
|
|||||||
writeLocked(fos, stats, version, packagesTokenData);
|
writeLocked(fos, stats, version, packagesTokenData);
|
||||||
file.finishWrite(fos);
|
file.finishWrite(fos);
|
||||||
fos = null;
|
fos = null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Do nothing. Exception has already been handled.
|
||||||
} finally {
|
} finally {
|
||||||
// When fos is null (successful write), this will no-op
|
// When fos is null (successful write), this will no-op
|
||||||
file.failWrite(fos);
|
file.failWrite(fos);
|
||||||
@@ -1032,7 +1034,7 @@ public class UsageStatsDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void writeLocked(OutputStream out, IntervalStats stats, int version,
|
private static void writeLocked(OutputStream out, IntervalStats stats, int version,
|
||||||
PackagesTokenData packagesTokenData) throws RuntimeException {
|
PackagesTokenData packagesTokenData) throws Exception {
|
||||||
switch (version) {
|
switch (version) {
|
||||||
case 1:
|
case 1:
|
||||||
case 2:
|
case 2:
|
||||||
@@ -1044,6 +1046,7 @@ public class UsageStatsDatabase {
|
|||||||
UsageStatsProto.write(out, stats);
|
UsageStatsProto.write(out, stats);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Slog.e(TAG, "Unable to write interval stats to proto.", e);
|
Slog.e(TAG, "Unable to write interval stats to proto.", e);
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
@@ -1052,6 +1055,7 @@ public class UsageStatsDatabase {
|
|||||||
UsageStatsProtoV2.write(out, stats);
|
UsageStatsProtoV2.write(out, stats);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Slog.e(TAG, "Unable to write interval stats to proto.", e);
|
Slog.e(TAG, "Unable to write interval stats to proto.", e);
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user