Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a18d2134 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Check for file existence before reading it."

parents 01a8c8db 4303dc06
Loading
Loading
Loading
Loading
+25 −20
Original line number Diff line number Diff line
@@ -13325,7 +13325,8 @@ public class BatteryStatsImpl extends BatteryStats {
            return;
        }
        if (mBatteryStatsHistory.getActiveFile() == null) {
        final AtomicFile activeHistoryFile = mBatteryStatsHistory.getActiveFile();
        if (activeHistoryFile == null) {
            Slog.w(TAG,
                    "readLocked: no history file associated with this instance");
            return;
@@ -13336,6 +13337,7 @@ public class BatteryStatsImpl extends BatteryStats {
        Parcel stats = Parcel.obtain();
        try {
            final long start = SystemClock.uptimeMillis();
            if (mStatsFile.exists()) {
                byte[] raw = mStatsFile.readFully();
                stats.unmarshall(raw, 0, raw.length);
                stats.setDataPosition(0);
@@ -13345,6 +13347,7 @@ public class BatteryStatsImpl extends BatteryStats {
                            + " bytes:" + raw.length + " takes ms:" + (SystemClock.uptimeMillis()
                            - start));
                }
            }
        } catch (Exception e) {
            Slog.e(TAG, "Error reading battery statistics", e);
            resetAllStatsLocked();
@@ -13355,7 +13358,8 @@ public class BatteryStatsImpl extends BatteryStats {
        Parcel history = Parcel.obtain();
        try {
            final long start = SystemClock.uptimeMillis();
            byte[] raw = mBatteryStatsHistory.getActiveFile().readFully();
            if (activeHistoryFile.exists()) {
                byte[] raw = activeHistoryFile.readFully();
                if (raw.length > 0) {
                    history.unmarshall(raw, 0, raw.length);
                    history.setDataPosition(0);
@@ -13363,10 +13367,11 @@ public class BatteryStatsImpl extends BatteryStats {
                }
                if (DEBUG) {
                    Slog.d(TAG, "readLocked history file::"
                        + mBatteryStatsHistory.getActiveFile().getBaseFile().getPath()
                            + activeHistoryFile.getBaseFile().getPath()
                            + " bytes:" + raw.length + " takes ms:" + (SystemClock.uptimeMillis()
                            - start));
                }
            }
        } catch (Exception e) {
            Slog.e(TAG, "Error reading battery history", e);
            clearHistoryLocked();