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

Commit 853fe283 authored by Dmitri Plotnikov's avatar Dmitri Plotnikov
Browse files

Allow empty battery history fragments

Bug: 399231397
Test: atest PowerStatsTests; atest PowerStatsTestsRavenwood
Flag: EXEMPT bugfix
Change-Id: If0f9d3cf45241450fe06c5090f3cf764dbc76b64
parent 9848646d
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -789,7 +789,7 @@ public class BatteryStatsHistory {
     */
    public boolean readFragmentToParcel(Parcel out, BatteryHistoryFragment fragment) {
        byte[] data = mStore.readFragment(fragment);
        if (data == null) {
        if (data == null || data.length == 0) {
            return false;
        }
        out.unmarshall(data, 0, data.length);
@@ -934,6 +934,10 @@ public class BatteryStatsHistory {
                    continue;
                }

                if (data.length == 0) {
                    continue;
                }

                out.writeBoolean(true);
                if (useBlobs) {
                    out.writeBlob(data, 0, data.length);
@@ -976,9 +980,11 @@ public class BatteryStatsHistory {
                return false;
            }

            if (data.length > 0) {
                parcel.unmarshall(data, 0, data.length);
                parcel.setDataPosition(0);
                readHistoryBuffer(parcel);
            }
        } catch (Exception e) {
            Slog.e(TAG, "Error reading battery history", e);
            reset();
+4 −0
Original line number Diff line number Diff line
@@ -251,6 +251,10 @@ public class BatteryHistoryDirectory implements BatteryStatsHistory.BatteryHisto
        try (FileInputStream stream = file.openRead()) {
            byte[] header = new byte[FILE_FORMAT_BYTES];
            if (stream.read(header, 0, FILE_FORMAT_BYTES) == -1) {
                if (file.getBaseFile().length() == 0) {
                    return new byte[0];
                }

                Slog.e(TAG, "Invalid battery history file format " + file.getBaseFile());
                deleteFragment(fragment);
                return null;