From 805cd476829e0ae1705cf5d4d4c45285a0b0c0cd Mon Sep 17 00:00:00 2001 From: aquilescanta Date: Thu, 10 Jun 2021 14:40:55 +0100 Subject: [PATCH] Add methods for comparing PlaybackException data Also replace the equals() method in MediaUtils. PiperOrigin-RevId: 378638642 --- .../exoplayer2/ExoPlaybackException.java | 17 ++++++++++ .../android/exoplayer2/PlaybackException.java | 33 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/library/common/src/main/java/com/google/android/exoplayer2/ExoPlaybackException.java b/library/common/src/main/java/com/google/android/exoplayer2/ExoPlaybackException.java index 7a156aa668..8a1bdcff70 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/ExoPlaybackException.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/ExoPlaybackException.java @@ -344,6 +344,23 @@ public final class ExoPlaybackException extends PlaybackException { return (RuntimeException) Assertions.checkNotNull(getCause()); } + @Override + public boolean errorInfoEquals(@Nullable PlaybackException that) { + if (!super.errorInfoEquals(that)) { + return false; + } + // We know that is not null and is an ExoPlaybackException because of the super call returning + // true. + ExoPlaybackException other = (ExoPlaybackException) Util.castNonNull(that); + return type == other.type + && Util.areEqual(rendererName, other.rendererName) + && rendererIndex == other.rendererIndex + && Util.areEqual(rendererFormat, other.rendererFormat) + && rendererFormatSupport == other.rendererFormatSupport + && Util.areEqual(mediaPeriodId, other.mediaPeriodId) + && isRecoverable == other.isRecoverable; + } + /** * Returns a copy of this exception with the provided {@link MediaPeriodId}. * diff --git a/library/common/src/main/java/com/google/android/exoplayer2/PlaybackException.java b/library/common/src/main/java/com/google/android/exoplayer2/PlaybackException.java index 81f2fe9ba3..58f18bdcb1 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/PlaybackException.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/PlaybackException.java @@ -23,6 +23,7 @@ import androidx.annotation.CallSuper; import androidx.annotation.IntDef; import androidx.annotation.Nullable; import com.google.android.exoplayer2.util.Clock; +import com.google.android.exoplayer2.util.Util; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -293,6 +294,38 @@ public class PlaybackException extends Exception implements Bundleable { this.timestampMs = timestampMs; } + /** + * Returns whether the error data associated to this exception equals the error data associated to + * {@code other}. + * + *

Note that this method does not compare the exceptions' stacktraces. + */ + @CallSuper + public boolean errorInfoEquals(@Nullable PlaybackException other) { + if (this == other) { + return true; + } + if (other == null || getClass() != other.getClass()) { + return false; + } + + @Nullable Throwable thisCause = getCause(); + @Nullable Throwable thatCause = other.getCause(); + if (thisCause != null && thatCause != null) { + if (!Util.areEqual(thisCause.getMessage(), thatCause.getMessage())) { + return false; + } + if (!Util.areEqual(thisCause.getClass(), thatCause.getClass())) { + return false; + } + } else if (thisCause != null || thatCause != null) { + return false; + } + return errorCode == other.errorCode + && Util.areEqual(getMessage(), other.getMessage()) + && timestampMs == other.timestampMs; + } + // Bundleable implementation. /**