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

Commit 623fd00c authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "PowerStatsLogger: ensure the opend stream is closed when IOException...

Merge "PowerStatsLogger: ensure the opend stream is closed when IOException happen." into main am: 0284d810 am: fb0fc2ab

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/3412242



Change-Id: I6f37e430250adcdfdcc8a6ef9d154221ac2309fb
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents ac7cf446 fb0fc2ab
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -285,14 +285,20 @@ public final class PowerStatsLogger extends Handler {
    }

    private void updateCacheFile(String cacheFilename, byte[] data) {
        AtomicFile atomicCachedFile = null;
        FileOutputStream fos = null;
        try {
            final AtomicFile atomicCachedFile =
            atomicCachedFile =
                    new AtomicFile(new File(mDataStoragePath, cacheFilename));
            final FileOutputStream fos = atomicCachedFile.startWrite();
            fos = atomicCachedFile.startWrite();
            fos.write(data);
            atomicCachedFile.finishWrite(fos);
        } catch (IOException e) {
            Slog.e(TAG, "Failed to write current data to cached file", e);
            if (fos != null) {
                atomicCachedFile.failWrite(fos);
            }
            return;
        }
    }