diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ImageExporter.java b/packages/SystemUI/src/com/android/systemui/screenshot/ImageExporter.java index 4aead817fe8c9..55602a98b8c57 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ImageExporter.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ImageExporter.java @@ -111,30 +111,21 @@ class ImageExporter { } /** - * Stores the given Bitmap to a temp file. + * Writes the given Bitmap to outputFile. */ - ListenableFuture exportAsTempFile(Executor executor, Bitmap bitmap) { + ListenableFuture exportToRawFile(Executor executor, Bitmap bitmap, + final File outputFile) { return CallbackToFutureAdapter.getFuture( (completer) -> { executor.execute(() -> { - File cachePath; - try { - cachePath = File.createTempFile("long_screenshot_cache_", ".tmp"); - try (FileOutputStream stream = new FileOutputStream(cachePath)) { - bitmap.compress(mCompressFormat, mQuality, stream); - } catch (IOException e) { - if (cachePath.exists()) { - //noinspection ResultOfMethodCallIgnored - cachePath.delete(); - cachePath = null; - } - completer.setException(e); - } - if (cachePath != null) { - completer.set(cachePath); - } + try (FileOutputStream stream = new FileOutputStream(outputFile)) { + bitmap.compress(mCompressFormat, mQuality, stream); + completer.set(outputFile); } catch (IOException e) { - // Failed to create a new file + if (outputFile.exists()) { + //noinspection ResultOfMethodCallIgnored + outputFile.delete(); + } completer.setException(e); } }); diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/LongScreenshotActivity.java b/packages/SystemUI/src/com/android/systemui/screenshot/LongScreenshotActivity.java index f571e417c6367..07f6d36cbec19 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/LongScreenshotActivity.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/LongScreenshotActivity.java @@ -228,8 +228,8 @@ public class LongScreenshotActivity extends Activity { }); // Immediately export to temp image file for saved state - mCacheSaveFuture = mImageExporter.exportAsTempFile(mBackgroundExecutor, - mLongScreenshot.toBitmap()); + mCacheSaveFuture = mImageExporter.exportToRawFile(mBackgroundExecutor, + mLongScreenshot.toBitmap(), new File(getCacheDir(), "long_screenshot_cache.png")); mCacheSaveFuture.addListener(() -> { try { // Get the temp file path to persist, used in onSavedInstanceState