Assign some more IO error codes

Specifically:
- ERROR_CODE_IO_NETWORK_CONNECTION_TIMEOUT
- ERROR_CODE_IO_NETWORK_CONNECTION_FAILED
- ERROR_CODE_IO_NETWORK_CONNECTION_CLOSED
PiperOrigin-RevId: 381441329
This commit is contained in:
aquilescanta 2021-06-25 12:06:07 +01:00 committed by Oliver Woodman
parent 465f7c06d8
commit b58fce1bd9

View File

@ -53,6 +53,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
import com.google.android.exoplayer2.upstream.BandwidthMeter; import com.google.android.exoplayer2.upstream.BandwidthMeter;
import com.google.android.exoplayer2.upstream.FileDataSource; import com.google.android.exoplayer2.upstream.FileDataSource;
import com.google.android.exoplayer2.upstream.HttpDataSource; import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.upstream.UdpDataSource;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Clock; import com.google.android.exoplayer2.util.Clock;
import com.google.android.exoplayer2.util.HandlerWrapper; import com.google.android.exoplayer2.util.HandlerWrapper;
@ -63,6 +64,7 @@ import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -615,10 +617,19 @@ import java.util.concurrent.atomic.AtomicBoolean;
handleIoException(e, PlaybackException.ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED); handleIoException(e, PlaybackException.ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED);
} catch (HttpDataSource.InvalidResponseCodeException e) { } catch (HttpDataSource.InvalidResponseCodeException e) {
handleIoException(e, PlaybackException.ERROR_CODE_IO_BAD_HTTP_STATUS); handleIoException(e, PlaybackException.ERROR_CODE_IO_BAD_HTTP_STATUS);
} catch (HttpDataSource.HttpDataSourceException e) { } catch (HttpDataSource.HttpDataSourceException | UdpDataSource.UdpDataSourceException e) {
@ErrorCode int errorCode; @ErrorCode int errorCode;
if (e.getCause() instanceof UnknownHostException) { @Nullable Throwable cause = e.getCause();
if (cause instanceof UnknownHostException) {
errorCode = PlaybackException.ERROR_CODE_IO_DNS_FAILED; errorCode = PlaybackException.ERROR_CODE_IO_DNS_FAILED;
} else if (cause instanceof SocketTimeoutException) {
errorCode = PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_TIMEOUT;
} else if (e instanceof HttpDataSource.HttpDataSourceException) {
int type = ((HttpDataSource.HttpDataSourceException) e).type;
errorCode =
type == HttpDataSource.HttpDataSourceException.TYPE_OPEN
? PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_FAILED
: PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_CLOSED;
} else { } else {
errorCode = PlaybackException.ERROR_CODE_IO_UNSPECIFIED; errorCode = PlaybackException.ERROR_CODE_IO_UNSPECIFIED;
} }