diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlaybackException.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlaybackException.java index 555f60ea1c..e8bea26feb 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlaybackException.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlaybackException.java @@ -254,19 +254,6 @@ public final class ExoPlaybackException extends PlaybackException { isRecoverable); } - private ExoPlaybackException(Bundle bundle) { - super(bundle); - type = bundle.getInt(FIELD_TYPE, /* defaultValue= */ TYPE_UNEXPECTED); - rendererName = bundle.getString(FIELD_RENDERER_NAME); - rendererIndex = bundle.getInt(FIELD_RENDERER_INDEX, /* defaultValue= */ C.INDEX_UNSET); - @Nullable Bundle rendererFormatBundle = bundle.getBundle(FIELD_RENDERER_FORMAT); - rendererFormat = rendererFormatBundle == null ? null : Format.fromBundle(rendererFormatBundle); - rendererFormatSupport = - bundle.getInt(FIELD_RENDERER_FORMAT_SUPPORT, /* defaultValue= */ C.FORMAT_HANDLED); - isRecoverable = bundle.getBoolean(FIELD_IS_RECOVERABLE, /* defaultValue= */ false); - mediaPeriodId = null; - } - private ExoPlaybackException( String message, @Nullable Throwable cause, @@ -399,44 +386,4 @@ public final class ExoPlaybackException extends PlaybackException { } return message; } - - /** Restores a {@code ExoPlaybackException} from a {@link Bundle}. */ - @UnstableApi - public static ExoPlaybackException fromBundle(Bundle bundle) { - return new ExoPlaybackException(bundle); - } - - private static final String FIELD_TYPE = Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 1); - private static final String FIELD_RENDERER_NAME = - Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 2); - private static final String FIELD_RENDERER_INDEX = - Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 3); - private static final String FIELD_RENDERER_FORMAT = - Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 4); - private static final String FIELD_RENDERER_FORMAT_SUPPORT = - Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 5); - private static final String FIELD_IS_RECOVERABLE = - Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 6); - - /** - * {@inheritDoc} - * - *

It omits the {@link #mediaPeriodId} field. The {@link #mediaPeriodId} of an instance - * restored by {@link #fromBundle} will always be {@code null}. - */ - @UnstableApi - @Override - public Bundle toBundle() { - Bundle bundle = super.toBundle(); - bundle.putInt(FIELD_TYPE, type); - bundle.putString(FIELD_RENDERER_NAME, rendererName); - bundle.putInt(FIELD_RENDERER_INDEX, rendererIndex); - if (rendererFormat != null) { - bundle.putBundle( - FIELD_RENDERER_FORMAT, rendererFormat.toBundle(/* excludeMetadata= */ false)); - } - bundle.putInt(FIELD_RENDERER_FORMAT_SUPPORT, rendererFormatSupport); - bundle.putBoolean(FIELD_IS_RECOVERABLE, isRecoverable); - return bundle; - } } diff --git a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/ExoPlaybackExceptionTest.java b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/ExoPlaybackExceptionTest.java deleted file mode 100644 index ef83608db5..0000000000 --- a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/ExoPlaybackExceptionTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package androidx.media3.exoplayer; - -import static com.google.common.truth.Truth.assertThat; - -import android.os.RemoteException; -import androidx.media3.common.C; -import androidx.media3.common.Format; -import androidx.media3.common.PlaybackException; -import androidx.media3.common.util.Util; -import androidx.test.ext.junit.runners.AndroidJUnit4; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** Unit tests for {@link ExoPlaybackException}. */ -@RunWith(AndroidJUnit4.class) -public class ExoPlaybackExceptionTest { - - @Test - public void roundTripViaBundle_ofExoPlaybackExceptionTypeRemote_yieldsEqualInstance() { - ExoPlaybackException before = ExoPlaybackException.createForRemote(/* message= */ "test"); - ExoPlaybackException after = ExoPlaybackException.fromBundle(before.toBundle()); - assertThat(areExoPlaybackExceptionsEqual(before, after)).isTrue(); - } - - @Test - public void roundTripViaBundle_ofExoPlaybackExceptionTypeRenderer_yieldsEqualInstance() { - ExoPlaybackException before = - ExoPlaybackException.createForRenderer( - new IllegalStateException("ExoPlaybackExceptionTest"), - /* rendererName= */ "rendererName", - /* rendererIndex= */ 123, - /* rendererFormat= */ new Format.Builder().setCodecs("anyCodec").build(), - /* rendererFormatSupport= */ C.FORMAT_UNSUPPORTED_SUBTYPE, - /* isRecoverable= */ true, - /* errorCode= */ PlaybackException.ERROR_CODE_DECODER_INIT_FAILED); - - ExoPlaybackException after = ExoPlaybackException.fromBundle(before.toBundle()); - assertThat(areExoPlaybackExceptionsEqual(before, after)).isTrue(); - } - - @Test - public void - roundTripViaBundle_ofExoPlaybackExceptionTypeUnexpectedWithPrivateCause_yieldsRemoteExceptionWithSameMessage() { - ExoPlaybackException before = - ExoPlaybackException.createForUnexpected( - new RuntimeException( - /* message= */ "anonymous exception that class loader cannot know") {}, - PlaybackException.ERROR_CODE_TIMEOUT); - ExoPlaybackException after = ExoPlaybackException.fromBundle(before.toBundle()); - - assertThat(after.getCause()).isInstanceOf(RemoteException.class); - assertThat(after.getCause()).hasMessageThat().isEqualTo(before.getCause().getMessage()); - } - - private static boolean areExoPlaybackExceptionsEqual( - ExoPlaybackException a, ExoPlaybackException b) { - if (a == null || b == null) { - return a == b; - } - return Util.areEqual(a.getMessage(), b.getMessage()) - && a.type == b.type - && Util.areEqual(a.rendererName, b.rendererName) - && a.rendererIndex == b.rendererIndex - && Util.areEqual(a.rendererFormat, b.rendererFormat) - && a.rendererFormatSupport == b.rendererFormatSupport - && a.timestampMs == b.timestampMs - && a.isRecoverable == b.isRecoverable - && areThrowablesEqual(a.getCause(), b.getCause()); - } - - private static boolean areThrowablesEqual(Throwable a, Throwable b) { - if (a == null || b == null) { - return a == b; - } - return a.getClass() == b.getClass() && Util.areEqual(a.getMessage(), b.getMessage()); - } -}