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

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

Merge "Add missing synchronization"

parents 321c9595 29f5e587
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -7640,7 +7640,9 @@ public abstract class BatteryStats {
     */
    @SuppressWarnings("unused")
    public void dump(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
        synchronized (this) {
            prepareForDumpLocked();
        }

        final boolean filtering = (flags
                & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
+11 −15
Original line number Diff line number Diff line
@@ -274,20 +274,6 @@ public class BatteryStatsHistory {
        initHistoryBuffer();
    }

    /**
     * Creates a read-only wrapper for the supplied writable history.
     */
    public BatteryStatsHistory(BatteryStatsHistory writableHistory) {
        this(Parcel.obtain(), writableHistory.mSystemDir, 0, 0, null, null, null, writableHistory);
        mMutable = false;

        synchronized (mWritableHistory) {
            // Make a copy of battery history to avoid concurrent modification.
            mHistoryBuffer.appendFrom(mWritableHistory.mHistoryBuffer, 0,
                    mWritableHistory.mHistoryBuffer.dataSize());
        }
    }

    @VisibleForTesting
    public BatteryStatsHistory(Parcel historyBuffer, File systemDir,
            int maxHistoryFiles, int maxHistoryBufferSize,
@@ -308,6 +294,9 @@ public class BatteryStatsHistory {
        mTracer = tracer;
        mClock = clock;
        mWritableHistory = writableHistory;
        if (mWritableHistory != null) {
            mMutable = false;
        }

        mHistoryDir = new File(systemDir, HISTORY_DIR);
        mHistoryDir.mkdirs();
@@ -415,7 +404,14 @@ public class BatteryStatsHistory {
     * in the system directory, so it is not safe while actively writing history.
     */
    public BatteryStatsHistory copy() {
        return new BatteryStatsHistory(this);
        synchronized (this) {
            // Make a copy of battery history to avoid concurrent modification.
            Parcel historyBufferCopy = Parcel.obtain();
            historyBufferCopy.appendFrom(mHistoryBuffer, 0, mHistoryBuffer.dataSize());

            return new BatteryStatsHistory(historyBufferCopy, mSystemDir, 0, 0, null, null, null,
                    this);
        }
    }

    /**