Clarify threading requirement for MediaController.releaseFuture

And remove unnecessary check for isDone.

Issue: androidx/media#345
PiperOrigin-RevId: 525999615
This commit is contained in:
tonihei 2023-04-21 12:39:10 +01:00 committed by Rohit Singh
parent 79fab6783e
commit 186f3d5c77

View File

@ -505,16 +505,19 @@ public class MediaController implements Player {
/**
* Releases the future controller returned by {@link Builder#buildAsync()}. It makes sure that the
* controller is released by canceling the future if the future is not yet done.
*
* <p>Must be called on the {@linkplain #getApplicationLooper() application thread} of the media
* controller.
*/
public static void releaseFuture(Future<? extends MediaController> controllerFuture) {
if (!controllerFuture.isDone()) {
controllerFuture.cancel(/* mayInterruptIfRunning= */ true);
if (controllerFuture.cancel(/* mayInterruptIfRunning= */ true)) {
// Successfully canceled the Future. The controller will be released by MediaControllerHolder.
return;
}
MediaController controller;
try {
controller = controllerFuture.get();
} catch (CancellationException | ExecutionException | InterruptedException e) {
controller = Futures.getDone(controllerFuture);
} catch (CancellationException | ExecutionException e) {
return;
}
controller.release();