Skip to content

Commit

Permalink
Clarify threading requirement for MediaController.releaseFuture
Browse files Browse the repository at this point in the history
And remove unnecessary check for isDone.

Issue: androidx/media#345
PiperOrigin-RevId: 525999615
  • Loading branch information
tonihei authored and rohitjoins committed Apr 24, 2023
1 parent 79fab67 commit 186f3d5
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -505,16 +505,19 @@ public final void release() {
/**
* 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();
Expand Down

0 comments on commit 186f3d5

Please sign in to comment.