diff options
| author | 2025-01-08 19:23:58 +0800 | |
|---|---|---|
| committer | 2025-01-08 19:23:58 +0800 | |
| commit | 19661358969f1f1c3ad52744f18d13a44340ed5a (patch) | |
| tree | 9ce5bb6f91be553903a06b68729d7a2d3a67664a | |
| parent | deab34dcbf1b3780aba4673284836c9de69bffcc (diff) | |
ensure the opend resources are eventually closed when IOException happen.
Bug: none
Flag: EXEMPT minor optimization
Change-Id: Ie4d86cc88de765cdb42270de44fa61cfb04c88d2
| -rw-r--r-- | services/core/java/com/android/server/wm/SnapshotPersistQueue.java | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/services/core/java/com/android/server/wm/SnapshotPersistQueue.java b/services/core/java/com/android/server/wm/SnapshotPersistQueue.java index 1c8c245f7640..67f4e563a2b1 100644 --- a/services/core/java/com/android/server/wm/SnapshotPersistQueue.java +++ b/services/core/java/com/android/server/wm/SnapshotPersistQueue.java @@ -354,10 +354,8 @@ class SnapshotPersistQueue { bitmap.recycle(); final File file = mPersistInfoProvider.getHighResolutionBitmapFile(mId, mUserId); - try { - FileOutputStream fos = new FileOutputStream(file); + try (FileOutputStream fos = new FileOutputStream(file)) { swBitmap.compress(JPEG, COMPRESS_QUALITY, fos); - fos.close(); } catch (IOException e) { Slog.e(TAG, "Unable to open " + file + " for persisting.", e); return false; @@ -375,10 +373,8 @@ class SnapshotPersistQueue { swBitmap.recycle(); final File lowResFile = mPersistInfoProvider.getLowResolutionBitmapFile(mId, mUserId); - try { - FileOutputStream lowResFos = new FileOutputStream(lowResFile); + try (FileOutputStream lowResFos = new FileOutputStream(lowResFile)) { lowResBitmap.compress(JPEG, COMPRESS_QUALITY, lowResFos); - lowResFos.close(); } catch (IOException e) { Slog.e(TAG, "Unable to open " + lowResFile + " for persisting.", e); return false; |