diff --git a/libraries/session/src/main/java/androidx/media3/session/MediaControllerImplBase.java b/libraries/session/src/main/java/androidx/media3/session/MediaControllerImplBase.java index c856873c1e..0a79cb07a3 100644 --- a/libraries/session/src/main/java/androidx/media3/session/MediaControllerImplBase.java +++ b/libraries/session/src/main/java/androidx/media3/session/MediaControllerImplBase.java @@ -2211,8 +2211,8 @@ import org.checkerframework.checker.nullness.qual.NonNull; try { MediaUtils.getFutureResult(future, /* timeoutMs= */ 3_000); } catch (ExecutionException e) { - // It never happens because future.setException will not be called anywhere - throw new AssertionError(e); + // Never happens because future.setException will not be called. + throw new IllegalStateException(e); } catch (TimeoutException e) { Log.w(TAG, "set/clearVideoSurface takes too long on the session side.", e); // TODO(b/188888693): Let developers know the failure in their code. @@ -2247,10 +2247,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; /** Returns session interface if the controller can send the predefined command. */ @Nullable IMediaSession getSessionInterfaceWithSessionCommandIfAble(@CommandCode int commandCode) { - if (commandCode == COMMAND_CODE_CUSTOM) { - throw new AssertionError( - "Use getSessionInterfaceWithSessionCommandIfAble(SessionCommand) for custom commands"); - } + checkArgument(commandCode != COMMAND_CODE_CUSTOM); if (!sessionCommands.contains(commandCode)) { Log.w(TAG, "Controller isn't allowed to call command, commandCode=" + commandCode); return null; @@ -2261,10 +2258,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; /** Returns session interface if the controller can send the custom command. */ @Nullable IMediaSession getSessionInterfaceWithSessionCommandIfAble(SessionCommand command) { - if (command.commandCode != COMMAND_CODE_CUSTOM) { - throw new AssertionError( - "Use getSessionInterfaceWithSessionCommandIfAble(int) for predefined commands"); - } + checkArgument(command.commandCode == COMMAND_CODE_CUSTOM); if (!sessionCommands.contains(command)) { Log.w(TAG, "Controller isn't allowed to call session command:" + command); return null; diff --git a/libraries/session/src/main/java/androidx/media3/session/MediaControllerImplLegacy.java b/libraries/session/src/main/java/androidx/media3/session/MediaControllerImplLegacy.java index aec3f925f5..2839d46101 100644 --- a/libraries/session/src/main/java/androidx/media3/session/MediaControllerImplLegacy.java +++ b/libraries/session/src/main/java/androidx/media3/session/MediaControllerImplLegacy.java @@ -280,7 +280,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; Uri.parse(pendingSetMediaUriRequest.value), pendingSetMediaUriRequest.extras); break; default: - throw new AssertionError("Unexpected type " + pendingSetMediaUriRequest.type); + throw new IllegalStateException("Unexpected type " + pendingSetMediaUriRequest.type); } pendingSetMediaUriRequest.result.set(new SessionResult(RESULT_SUCCESS)); pendingSetMediaUriRequest = null; @@ -345,7 +345,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; Uri.parse(pendingSetMediaUriRequest.value), pendingSetMediaUriRequest.extras); break; default: - throw new AssertionError("Unexpected type " + pendingSetMediaUriRequest.type); + throw new IllegalStateException("Unexpected type " + pendingSetMediaUriRequest.type); } pendingSetMediaUriRequest.result.set(new SessionResult(RESULT_SUCCESS)); pendingSetMediaUriRequest = null; diff --git a/libraries/session/src/main/java/androidx/media3/session/MediaLibrarySessionImpl.java b/libraries/session/src/main/java/androidx/media3/session/MediaLibrarySessionImpl.java index 0a13eb48cb..f33347f961 100644 --- a/libraries/session/src/main/java/androidx/media3/session/MediaLibrarySessionImpl.java +++ b/libraries/session/src/main/java/androidx/media3/session/MediaLibrarySessionImpl.java @@ -292,12 +292,7 @@ import java.util.concurrent.Future; if (result.resultCode == RESULT_SUCCESS) { List items = checkNotNull(result.value); if (items.size() > pageSize) { - throw new AssertionError( - "The number of items must be less than or equal to the pageSize" - + ", size=" - + items.size() - + ", pageSize=" - + pageSize); + throw new IllegalStateException("Invalid size=" + items.size() + ", pageSize=" + pageSize); } } } diff --git a/libraries/session/src/main/java/androidx/media3/session/MediaUtils.java b/libraries/session/src/main/java/androidx/media3/session/MediaUtils.java index 46dc427e5e..6fac95e8ec 100644 --- a/libraries/session/src/main/java/androidx/media3/session/MediaUtils.java +++ b/libraries/session/src/main/java/androidx/media3/session/MediaUtils.java @@ -646,7 +646,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; return MediaDescriptionCompat.BT_FOLDER_TYPE_YEARS; case MediaMetadata.FOLDER_TYPE_NONE: default: - throw new AssertionError("Unsupported folder type " + folderType); + throw new IllegalArgumentException("Unrecognized FolderType: " + folderType); } } @@ -743,15 +743,14 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; case Player.STATE_IDLE: return PlaybackStateCompat.STATE_NONE; case Player.STATE_READY: + case Player.STATE_ENDED: return PlaybackStateCompat.STATE_PAUSED; case Player.STATE_BUFFERING: return playWhenReady ? PlaybackStateCompat.STATE_BUFFERING : PlaybackStateCompat.STATE_PAUSED; - case Player.STATE_ENDED: - return PlaybackStateCompat.STATE_PAUSED; default: - throw new AssertionError("Playback state shouldn't be " + playbackState); + throw new IllegalArgumentException("Unrecognized State: " + playbackState); } } @@ -820,8 +819,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; convertToCurrentPositionMs(playbackStateCompat, currentMediaMetadata, timeDiffMs); return (currentPosition < duration) ? Player.STATE_READY : Player.STATE_ENDED; default: - throw new AssertionError( - "PlaybackStateCompat.State shouldn't be " + playbackStateCompat.getState()); + throw new IllegalStateException( + "Unrecognized PlaybackStateCompat: " + playbackStateCompat.getState()); } } @@ -947,8 +946,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; case PlaybackStateCompat.REPEAT_MODE_GROUP: return Player.REPEAT_MODE_ALL; default: - throw new AssertionError( - "PlaybackStateCompat repeat mode shouldn't be " + playbackStateCompatRepeatMode); + throw new IllegalArgumentException( + "Unrecognized PlaybackStateCompat.RepeatMode: " + playbackStateCompatRepeatMode); } } @@ -963,7 +962,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; case Player.REPEAT_MODE_ALL: return PlaybackStateCompat.REPEAT_MODE_ALL; default: - throw new AssertionError("Player.RepeatMode shouldn't be " + repeatMode); + throw new IllegalArgumentException("Unrecognized RepeatMode: " + repeatMode); } } @@ -978,8 +977,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; case PlaybackStateCompat.SHUFFLE_MODE_GROUP: return true; default: - throw new AssertionError( - "PlaybackStateCompat.ShuffleMode shouldn't be " + playbackStateCompatShuffleMode); + throw new IllegalArgumentException( + "Unrecognized ShuffleMode: " + playbackStateCompatShuffleMode); } }