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

Commit ca1d4453 authored by Dmitri Plotnikov's avatar Dmitri Plotnikov Committed by Android (Google) Code Review
Browse files

Merge "Allow empty battery history fragments" into main

parents fd356738 853fe283
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;