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

Commit 5a92f913 authored by Matt Casey's avatar Matt Casey Committed by Automerger Merge Worker
Browse files

Merge "Always save long screenshot temp file to the same place" into sc-dev am: 4bb1104c

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

Change-Id: I8742f49599e7328b0092861c2315022a3e969a9f
parents c4935408 4bb1104c
Loading
Loading
Loading
Loading
+10 −19
Original line number Diff line number Diff line
@@ -111,30 +111,21 @@ class ImageExporter {
    }

    /**
     * Stores the given Bitmap to a temp file.
     * Writes the given Bitmap to outputFile.
     */
    ListenableFuture<File> exportAsTempFile(Executor executor, Bitmap bitmap) {
    ListenableFuture<File> 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)) {
                        try (FileOutputStream stream = new FileOutputStream(outputFile)) {
                            bitmap.compress(mCompressFormat, mQuality, stream);
                            completer.set(outputFile);
                        } catch (IOException e) {
                                if (cachePath.exists()) {
                            if (outputFile.exists()) {
                                //noinspection ResultOfMethodCallIgnored
                                    cachePath.delete();
                                    cachePath = null;
                                }
                                completer.setException(e);
                                outputFile.delete();
                            }
                            if (cachePath != null) {
                                completer.set(cachePath);
                            }
                        } catch (IOException e) {
                            // Failed to create a new file
                            completer.setException(e);
                        }
                    });
+2 −2
Original line number Diff line number Diff line
@@ -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