114 lines
5.5 KiB
Java
114 lines
5.5 KiB
Java
|
package com.huawei.hms.framework.common;
|
||
|
|
||
|
import android.text.TextUtils;
|
||
|
import java.io.IOException;
|
||
|
import java.io.InterruptedIOException;
|
||
|
import java.net.ConnectException;
|
||
|
import java.net.NoRouteToHostException;
|
||
|
import java.net.ProtocolException;
|
||
|
import java.net.SocketTimeoutException;
|
||
|
import java.net.UnknownHostException;
|
||
|
import javax.net.ssl.SSLHandshakeException;
|
||
|
import javax.net.ssl.SSLPeerUnverifiedException;
|
||
|
import javax.net.ssl.SSLProtocolException;
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
public class ExceptionCode {
|
||
|
public static final int CANCEL = 10000100;
|
||
|
private static final String CONNECT = "connect";
|
||
|
public static final int CONNECTION_ABORT = 10000402;
|
||
|
public static final int CONNECTION_REFUSED = 10000404;
|
||
|
public static final int CONNECTION_RESET = 10000401;
|
||
|
public static final int CONNECT_FAILED = 10000403;
|
||
|
public static final int CRASH_EXCEPTION = 10000000;
|
||
|
public static final int INTERRUPT_CONNECT_CLOSE = 10000405;
|
||
|
public static final int INTERRUPT_EXCEPTION = 10000804;
|
||
|
public static final int NETWORK_CHANGED = 10000201;
|
||
|
public static final int NETWORK_IO_EXCEPTION = 10000802;
|
||
|
public static final int NETWORK_TIMEOUT = 10000101;
|
||
|
public static final int NETWORK_UNREACHABLE = 10000200;
|
||
|
public static final int NETWORK_UNSUPPORTED = 10000102;
|
||
|
public static final int PROTOCOL_ERROR = 10000801;
|
||
|
private static final String READ = "read";
|
||
|
public static final int READ_ERROR = 10000601;
|
||
|
public static final int ROUTE_FAILED = 10000301;
|
||
|
public static final int SHUTDOWN_EXCEPTION = 10000202;
|
||
|
public static final int SOCKET_CLOSE = 10000406;
|
||
|
public static final int SOCKET_CONNECT_TIMEOUT = 10000400;
|
||
|
public static final int SOCKET_READ_TIMEOUT = 10000600;
|
||
|
public static final int SOCKET_TIMEOUT = 10000803;
|
||
|
public static final int SOCKET_WRITE_TIMEOUT = 10000700;
|
||
|
public static final int SSL_HANDSHAKE_EXCEPTION = 10000501;
|
||
|
public static final int SSL_PEERUNVERIFIED_EXCEPTION = 10000502;
|
||
|
public static final int SSL_PROTOCOL_EXCEPTION = 10000500;
|
||
|
public static final int UNABLE_TO_RESOLVE_HOST = 10000300;
|
||
|
public static final int UNEXPECTED_EOF = 10000800;
|
||
|
private static final String WRITE = "write";
|
||
|
|
||
|
public static int getErrorCodeFromException(Exception exc) {
|
||
|
if (exc == null) {
|
||
|
return NETWORK_IO_EXCEPTION;
|
||
|
}
|
||
|
if (!(exc instanceof IOException)) {
|
||
|
return CRASH_EXCEPTION;
|
||
|
}
|
||
|
String message = exc.getMessage();
|
||
|
if (message == null) {
|
||
|
return NETWORK_IO_EXCEPTION;
|
||
|
}
|
||
|
String lowerCase = StringUtils.toLowerCase(message);
|
||
|
int errorCodeFromMsg = getErrorCodeFromMsg(lowerCase);
|
||
|
if (errorCodeFromMsg != 10000802) {
|
||
|
return errorCodeFromMsg;
|
||
|
}
|
||
|
if (exc instanceof SocketTimeoutException) {
|
||
|
return getErrorCodeSocketTimeout(exc);
|
||
|
}
|
||
|
return exc instanceof ConnectException ? CONNECT_FAILED : exc instanceof NoRouteToHostException ? ROUTE_FAILED : exc instanceof SSLProtocolException ? SSL_PROTOCOL_EXCEPTION : exc instanceof SSLHandshakeException ? SSL_HANDSHAKE_EXCEPTION : exc instanceof SSLPeerUnverifiedException ? SSL_PEERUNVERIFIED_EXCEPTION : exc instanceof UnknownHostException ? UNABLE_TO_RESOLVE_HOST : exc instanceof InterruptedIOException ? lowerCase.contains("connection has been shut down") ? INTERRUPT_CONNECT_CLOSE : INTERRUPT_EXCEPTION : exc instanceof ProtocolException ? PROTOCOL_ERROR : errorCodeFromMsg;
|
||
|
}
|
||
|
|
||
|
private static int getErrorCodeSocketTimeout(Exception exc) {
|
||
|
char c;
|
||
|
String checkExceptionContainsKey = checkExceptionContainsKey(exc, CONNECT, READ, WRITE);
|
||
|
checkExceptionContainsKey.hashCode();
|
||
|
int hashCode = checkExceptionContainsKey.hashCode();
|
||
|
if (hashCode == 3496342) {
|
||
|
if (checkExceptionContainsKey.equals(READ)) {
|
||
|
c = 0;
|
||
|
}
|
||
|
c = 65535;
|
||
|
} else if (hashCode != 113399775) {
|
||
|
if (hashCode == 951351530 && checkExceptionContainsKey.equals(CONNECT)) {
|
||
|
c = 2;
|
||
|
}
|
||
|
c = 65535;
|
||
|
} else {
|
||
|
if (checkExceptionContainsKey.equals(WRITE)) {
|
||
|
c = 1;
|
||
|
}
|
||
|
c = 65535;
|
||
|
}
|
||
|
return c != 0 ? c != 1 ? c != 2 ? SOCKET_TIMEOUT : SOCKET_CONNECT_TIMEOUT : SOCKET_WRITE_TIMEOUT : SOCKET_READ_TIMEOUT;
|
||
|
}
|
||
|
|
||
|
private static int getErrorCodeFromMsg(String str) {
|
||
|
return str.contains("unexpected end of stream") ? UNEXPECTED_EOF : str.contains("unable to resolve host") ? UNABLE_TO_RESOLVE_HOST : str.contains("read error") ? READ_ERROR : str.contains("connection reset") ? CONNECTION_RESET : str.contains("software caused connection abort") ? CONNECTION_ABORT : str.contains("failed to connect to") ? CONNECT_FAILED : str.contains("connection refused") ? CONNECTION_REFUSED : str.contains("connection timed out") ? SOCKET_CONNECT_TIMEOUT : str.contains("no route to host") ? ROUTE_FAILED : str.contains("network is unreachable") ? NETWORK_UNREACHABLE : str.contains("socket closed") ? SOCKET_CLOSE : NETWORK_IO_EXCEPTION;
|
||
|
}
|
||
|
|
||
|
private static String checkExceptionContainsKey(Exception exc, String... strArr) {
|
||
|
return checkStrContainsKey(StringUtils.toLowerCase(exc.getMessage()), strArr);
|
||
|
}
|
||
|
|
||
|
private static String checkStrContainsKey(String str, String... strArr) {
|
||
|
if (TextUtils.isEmpty(str)) {
|
||
|
return "";
|
||
|
}
|
||
|
for (String str2 : strArr) {
|
||
|
if (str.contains(str2)) {
|
||
|
return str2;
|
||
|
}
|
||
|
}
|
||
|
return "";
|
||
|
}
|
||
|
}
|