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

Commit 4890cbe7 authored by Miranda Kephart's avatar Miranda Kephart
Browse files

Add a timeout when loading and releasing screenshot shutter sound

Right now, we load the sound on the background but must release
it on the main thread since the service is being destroyed. There's
currently no timeout, so if the sound fails to load for some reason
this will never succeed and will block forever. This means that
once the screenshots process attempts destruction (e.g. when the UI
is dismissed) no further screenshots can be taken.

This change adds a timeout so that even if the camera sound fails
to load, the process is still able to close successfully.

Bug: 273688513
Test: manual; take successive screenshots on a device where audio load
fails (see bug)
Change-Id: I0801c39547304cbab15c5f0589298002e1c7c70a

Change-Id: Ica277e15a1c55d1e5487d4791bd1dce137c35674
parent 5895ed66
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -115,6 +115,8 @@ import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Consumer;
import java.util.function.Supplier;

@@ -613,11 +615,13 @@ public class ScreenshotController {
        // Note that this may block if the sound is still being loaded (very unlikely) but we can't
        // reliably release in the background because the service is being destroyed.
        try {
            MediaPlayer player = mCameraSound.get();
            MediaPlayer player = mCameraSound.get(1, TimeUnit.SECONDS);
            if (player != null) {
                player.release();
            }
        } catch (InterruptedException | ExecutionException e) {
        } catch (InterruptedException | ExecutionException | TimeoutException e) {
            mCameraSound.cancel(true);
            Log.w(TAG, "Error releasing shutter sound", e);
        }
    }