From 3d865240e776374ced4ea50e6cb7f8ac92a32640 Mon Sep 17 00:00:00 2001 From: Per Andersson Date: Mon, 21 Feb 2011 09:55:42 +0100 Subject: [PATCH] Adding a sanity test in the while loop in readHistory() Adding a sanity test in the while loop in readHistory() which is useful in case the file read (batterystats.bin), is corrupt. The file can get corrupt (missing end of file marker -1) if writeHistory fails for some reason. Without this change readHistory will continue looping untill an OutOfMemory is thrown. Change-Id: I3418d258e7cb99aa2f9d934c9449a19806499ce4 --- core/java/com/android/internal/os/BatteryStatsImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java index fb4dff8e5dd05..5b9c78cc312cf 100644 --- a/core/java/com/android/internal/os/BatteryStatsImpl.java +++ b/core/java/com/android/internal/os/BatteryStatsImpl.java @@ -4563,7 +4563,7 @@ public final class BatteryStatsImpl extends BatteryStats { mHistory = mHistoryEnd = mHistoryCache = null; mHistoryBaseTime = 0; long time; - while ((time=in.readLong()) >= 0) { + while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { HistoryItem rec = new HistoryItem(time, in); addHistoryRecordLocked(rec); if (rec.time > mHistoryBaseTime) {