diff options
author | Takashi Nagaya <Takashi.X.Nagaya@sony.com> | 2020-12-28 14:33:23 +0900 |
---|---|---|
committer | Koji Fukui <Koji.Fukui@sony.com> | 2021-01-14 20:57:09 +0900 |
commit | f740b56f0e6896367be1cf70d63ef3ff291300fa (patch) | |
tree | 50921a6c1270b46287bcc0ac41ac06cf8935c2d5 | |
parent | 539dbe61c57234512ced37daa5a284009ade50f6 (diff) |
Fixed to prevent usagestats file corruption when writing
Currently, usagestats file may be currupted when writing
fails. Because AtomicFile#failWrite(fos) is always called
with argument null. Modify argument of this method so that
it is not null when writing fails.
Bug: 177501256
Change-Id: I1bb64a9af7941ab80abe3f98ad5b8ecf6d1b46d6
-rw-r--r-- | services/usage/java/com/android/server/usage/UsageStatsDatabase.java | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/services/usage/java/com/android/server/usage/UsageStatsDatabase.java b/services/usage/java/com/android/server/usage/UsageStatsDatabase.java index 9d48955c87be..e5672081464e 100644 --- a/services/usage/java/com/android/server/usage/UsageStatsDatabase.java +++ b/services/usage/java/com/android/server/usage/UsageStatsDatabase.java @@ -1025,6 +1025,8 @@ public class UsageStatsDatabase { writeLocked(fos, stats, version, packagesTokenData); file.finishWrite(fos); fos = null; + } catch (Exception e) { + // Do nothing. Exception has already been handled. } finally { // When fos is null (successful write), this will no-op file.failWrite(fos); @@ -1032,7 +1034,7 @@ public class UsageStatsDatabase { } private static void writeLocked(OutputStream out, IntervalStats stats, int version, - PackagesTokenData packagesTokenData) throws RuntimeException { + PackagesTokenData packagesTokenData) throws Exception { switch (version) { case 1: case 2: @@ -1044,6 +1046,7 @@ public class UsageStatsDatabase { UsageStatsProto.write(out, stats); } catch (Exception e) { Slog.e(TAG, "Unable to write interval stats to proto.", e); + throw e; } break; case 5: @@ -1052,6 +1055,7 @@ public class UsageStatsDatabase { UsageStatsProtoV2.write(out, stats); } catch (Exception e) { Slog.e(TAG, "Unable to write interval stats to proto.", e); + throw e; } break; default: |