Commit 805cd476 by aquilescanta Committed by Oliver Woodman

Add methods for comparing PlaybackException data

Also replace the equals() method in MediaUtils.

PiperOrigin-RevId: 378638642
parent b5dbadee
......@@ -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}.
*
......
......@@ -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}.
*
* <p>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.
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment