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

Commit e83df489 authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

Avoid cross lock acquisition leading to deadlocks

Test: manual

bug:36007738

Change-Id: I3db09af07857435682754916849433a809547974
parent 7f611633
Loading
Loading
Loading
Loading
+18 −14
Original line number Diff line number Diff line
@@ -553,13 +553,7 @@ final class SettingsState {
    }

    private void doWriteState() {
        synchronized (mWriteLock) {
            if (DEBUG_PERSISTENCE) {
                Slog.i(LOG_TAG, "[PERSIST START]");
            }

            AtomicFile destination = new AtomicFile(mStatePersistFile);

        boolean wroteState = false;
        final int version;
        final ArrayMap<String, Setting> settings;

@@ -570,6 +564,12 @@ final class SettingsState {
            mWriteScheduled = false;
        }

        synchronized (mWriteLock) {
            if (DEBUG_PERSISTENCE) {
                Slog.i(LOG_TAG, "[PERSIST START]");
            }

            AtomicFile destination = new AtomicFile(mStatePersistFile);
            FileOutputStream out = null;
            try {
                out = destination.startWrite();
@@ -600,9 +600,7 @@ final class SettingsState {
                serializer.endDocument();
                destination.finishWrite(out);

                synchronized (mLock) {
                    addHistoricalOperationLocked(HISTORICAL_OPERATION_PERSIST, null);
                }
                wroteState = true;

                if (DEBUG_PERSISTENCE) {
                    Slog.i(LOG_TAG, "[PERSIST END]");
@@ -614,6 +612,12 @@ final class SettingsState {
                IoUtils.closeQuietly(out);
            }
        }

        if (wroteState) {
            synchronized (mLock) {
                addHistoricalOperationLocked(HISTORICAL_OPERATION_PERSIST, null);
            }
        }
    }

    static void writeSingleSetting(int version, XmlSerializer serializer, String id,