华润电力 v1.2.3版本的 MD5 值为:cad684e77a7ed4d9f34cd67128f7a0db
以下内容为反编译后的 SpdyAgent.java 源代码,内容仅作参考
package org.android.spdy;
import android.content.Context;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public final class SpdyAgent {
private static final boolean HAVE_CLOSE = false;
private static final int KB32 = 32768;
private static final int KB8 = 8192;
private static final int MAX_SPDY_SESSION_COUNT = 50;
private static final int MB5 = 5242880;
static final int MODE_QUIC = 256;
static final int SPDY_CUSTOM_CONTROL_FRAME_RECV = 4106;
static final int SPDY_DATA_CHUNK_RECV = 4097;
static final int SPDY_DATA_RECV = 4098;
static final int SPDY_DATA_SEND = 4099;
static final int SPDY_PING_RECV = 4101;
private static final int SPDY_PROTOCAL = 2;
static final int SPDY_REQUEST_RECV = 4102;
static final int SPDY_SESSION_CLOSE = 4103;
static final int SPDY_SESSION_CREATE = 4096;
static final int SPDY_SESSION_FAILED_ERROR = 4105;
static final int SPDY_STREAM_CLOSE = 4100;
static final int SPDY_STREAM_RESPONSE_RECV = 4104;
public static volatile boolean enableDebug = false;
public static volatile boolean enableTimeGaurd = false;
private int agentNativePtr;
private static final ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock();
private static final Lock r = rwLock.readLock();
private static final Lock w = rwLock.writeLock();
private static SpdyAgent gSingleInstance = null;
private static Object lock = new Object();
private HashMap<String, SpdySession> sessionMgr = new HashMap<>(5);
private LinkedList<SpdySession> sessionQueue = new LinkedList<>();
private AtomicBoolean closed = new AtomicBoolean();
private String proxyUsername = null;
private String proxyPassword = null;
private native int closeSessionN(int i);
private native int configLogFileN(String str, int i, int i2);
private native int configLogFileN(String str, int i, int i2, int i3);
private static void crashReporter(int i) {
}
private native long createSession(int i, SpdySession spdySession, byte[] bArr, char c, byte[] bArr2, char c2, byte[] bArr3, byte[] bArr4, Object obj, int i2);
private native int freeAgent(int i);
private native int getSession(int i, byte[] bArr, char c);
private native int initAgent(int i, int i2, int i3);
private static native void inspectN(String str);
private native void logFileCloseN();
private native void logFileFlushN();
private native int setConTimeout(int i, int i2);
private native int setSessionKind(int i, int i2);
private native long submitRequest(int i, SpdySession spdySession, byte[] bArr, char c, byte[] bArr2, char c2, byte[] bArr3, byte[] bArr4, byte[] bArr5, byte b, String[] strArr, byte[] bArr6, boolean z, Object obj, int i2, int i3, int i4, int i5, int i6);
public void close() {
}
public void clearSpdySession(String str) {
if (str != null) {
w.lock();
if (str != null) {
try {
try {
this.sessionMgr.remove(str);
} catch (Throwable th) {
th.printStackTrace();
}
} finally {
w.unlock();
}
}
}
}
public static SpdyAgent getInstance(Context context, SpdyVersion spdyVersion, SpdySessionKind spdySessionKind) throws UnsatisfiedLinkError, SpdyErrorException {
if (gSingleInstance == null) {
synchronized (lock) {
if (gSingleInstance == null) {
gSingleInstance = new SpdyAgent(context, spdyVersion, spdySessionKind);
}
}
}
return gSingleInstance;
}
private SpdyAgent(Context context, SpdyVersion spdyVersion, SpdySessionKind spdySessionKind) throws UnsatisfiedLinkError {
try {
SoInstallMgrSdk.init(context);
SoInstallMgrSdk.initSo("tnet-2.0.17.1-agoo", 1);
} catch (Throwable th) {
th.printStackTrace();
}
try {
this.agentNativePtr = initAgent(spdyVersion.getInt(), spdySessionKind.getint(), 0);
} catch (UnsatisfiedLinkError e) {
e.printStackTrace();
}
this.closed.set(false);
}
public SpdySession getSession(SpdyRequest spdyRequest) throws SpdyErrorException {
if (spdyRequest == null) {
throw new SpdyErrorException("SPDY_JNI_ERR_INVALID_PARAM", TnetStatusCode.TNET_JNI_ERR_INVLID_PARAM);
}
agentIsOpen();
r.lock();
try {
return this.sessionMgr.get(spdyRequest.getAuthority());
} finally {
r.unlock();
}
}
public void setProxyUsernamePassword(String str, String str2) {
this.proxyUsername = str;
this.proxyPassword = str2;
}
static void securityCheck(int i, int i2) {
if (i >= 32768) {
throw new SpdyErrorException("SPDY_JNI_ERR_INVALID_PARAM:total=" + i, TnetStatusCode.TNET_JNI_ERR_INVLID_PARAM);
}
if (i2 < 8192) {
return;
}
throw new SpdyErrorException("SPDY_JNI_ERR_INVALID_PARAM:value=" + i2, TnetStatusCode.TNET_JNI_ERR_INVLID_PARAM);
}
static void tableListJudge(int i) {
if (i < MB5) {
return;
}
throw new SpdyErrorException("SPDY_JNI_ERR_INVALID_PARAM:total=" + i, TnetStatusCode.TNET_JNI_ERR_INVLID_PARAM);
}
static void InvlidCharJudge(byte[] bArr, byte[] bArr2) {
for (int i = 0; i < bArr.length; i++) {
if ((bArr[i] & 255) < 32 || (bArr[i] & 255) > 126) {
bArr[i] = 63;
}
}
for (int i2 = 0; i2 < bArr2.length; i2++) {
if ((bArr2[i2] & 255) < 32 || (bArr2[i2] & 255) > 126) {
bArr2[i2] = 63;
}
}
}
static void headJudge(Map<String, String> map) {
if (map != null) {
int i = 0;
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
InvlidCharJudge(key.getBytes(), value.getBytes());
i += key.length() + 1 + value.length();
securityCheck(i, value.length());
}
}
}
static String mapBodyToString(Map<String, String> map) {
StringBuilder sb = new StringBuilder();
if (map == null) {
return null;
}
int i = 0;
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
sb.append(key);
sb.append('=');
sb.append(value);
sb.append('&');
i += key.length() + 1 + value.length();
tableListJudge(i);
}
if (sb.length() > 0) {
sb.setLength(sb.length() - 1);
}
return sb.toString();
}
public static byte[] dataproviderToByteArray(SpdyRequest spdyRequest, SpdyDataProvider spdyDataProvider) {
byte[] bArr;
headJudge(spdyRequest.getHeaders());
if (spdyDataProvider == null) {
return null;
}
String mapBodyToString = mapBodyToString(spdyDataProvider.postBody);
if (mapBodyToString != null) {
bArr = mapBodyToString.getBytes();
} else {
bArr = spdyDataProvider.data;
}
if (bArr == null || bArr.length < MB5) {
return bArr;
}
throw new SpdyErrorException("SPDY_JNI_ERR_INVALID_PARAM:total=" + bArr.length, TnetStatusCode.TNET_JNI_ERR_INVLID_PARAM);
}
public SpdySession createSession(String str, Object obj, SessionCb sessionCb) throws SpdyErrorException {
String str2;
byte[] bArr;
char c;
SpdySession spdySession;
long createSession;
if (obj == null || str == null) {
throw new SpdyErrorException("SPDY_JNI_ERR_INVALID_PARAM", TnetStatusCode.TNET_JNI_ERR_INVLID_PARAM);
}
String[] split = str.split("/");
String[] split2 = split[0].split(":");
byte[] bytes = "0.0.0.0".getBytes();
if (split.length != 1) {
String[] split3 = split[1].split(":");
byte[] bytes2 = split3[0].getBytes();
str2 = str;
c = (char) Integer.parseInt(split3[1]);
bArr = bytes2;
} else {
str2 = str + "/0.0.0.0:0";
bArr = bytes;
c = 0;
}
agentIsOpen();
r.lock();
try {
SpdySession spdySession2 = this.sessionMgr.get(str2);
if (this.sessionMgr.size() >= 50) {
throw new SpdyErrorException("SPDY_SESSION_EXCEED_MAXED: session count exceed max", TnetStatusCode.TNET_SESSION_EXCEED_MAXED);
}
if (spdySession2 != null) {
return spdySession2;
}
w.lock();
SpdySession spdySession3 = null;
try {
spdySession = this.sessionMgr.get(str2);
} catch (Throwable unused) {
spdySession = null;
}
if (spdySession != null) {
return spdySession;
}
try {
SpdySession spdySession4 = new SpdySession(0, this, str2, sessionCb);
if (this.proxyUsername != null && this.proxyPassword != null) {
createSession = createSession(this.agentNativePtr, spdySession4, split2[0].getBytes(), (char) Integer.parseInt(split2[1]), bArr, c, this.proxyUsername.getBytes(), this.proxyPassword.getBytes(), obj, 2);
} else {
createSession = createSession(this.agentNativePtr, spdySession4, split2[0].getBytes(), (char) Integer.parseInt(split2[1]), bArr, c, null, null, obj, 2);
}
spduLog.Logi("tnet-jni", " create new session: " + str);
int i = (int) (createSession & (-1));
int i2 = (int) ((createSession >> 32) & (-1));
if (i != 0) {
spdySession4.setSessionNativePtr(i);
this.sessionMgr.put(str2, spdySession4);
this.sessionQueue.add(spdySession4);
spdySession3 = spdySession4;
} else if (i2 != 0) {
throw new SpdyErrorException("create session error: " + i2, i2);
}
return spdySession3;
} finally {
w.unlock();
}
} finally {
r.unlock();
}
}
public int closeSession(String str) {
SpdySession spdySession;
String[] split = str.split("/");
byte[] bytes = "0.0.0.0".getBytes();
if (split.length != 1) {
String[] split2 = split[1].split(":");
split2[0].getBytes();
Integer.parseInt(split2[1]);
} else {
str = str + "/" + bytes + ":\u0000";
}
agentIsOpen();
w.lock();
try {
spdySession = this.sessionMgr.get(str);
} catch (Throwable unused) {
spdySession = null;
}
if (spdySession == null) {
w.unlock();
return -1;
}
try {
return spdySession.closeSession();
} finally {
w.unlock();
}
}
public SpdySession submitRequest(SpdyRequest spdyRequest, SpdyDataProvider spdyDataProvider, Object obj, Object obj2, Spdycb spdycb, SessionCb sessionCb, int i) throws SpdyErrorException {
SpdySession spdySession;
int i2;
SpdySession spdySession2;
long submitRequest;
int i3;
SpdySession spdySession3;
SpdyAgent spdyAgent = this;
if (spdyRequest == null || obj2 == null || spdyRequest.getAuthority() == null) {
throw new SpdyErrorException("SPDY_JNI_ERR_INVALID_PARAM", TnetStatusCode.TNET_JNI_ERR_INVLID_PARAM);
}
agentIsOpen();
r.lock();
try {
SpdySession spdySession4 = spdyAgent.sessionMgr.get(spdyRequest.getAuthority());
if (spdyAgent.sessionMgr.size() >= 50) {
throw new SpdyErrorException("SPDY_SESSION_EXCEED_MAXED:session count exceed max", TnetStatusCode.TNET_SESSION_EXCEED_MAXED);
}
if (spdySession4 != null) {
spdySession4.submitRequest(spdyRequest, spdyDataProvider, obj2, spdycb);
return spdySession4;
}
byte[] dataproviderToByteArray = dataproviderToByteArray(spdyRequest, spdyDataProvider);
byte[] bArr = (dataproviderToByteArray == null || dataproviderToByteArray.length > 0) ? dataproviderToByteArray : null;
boolean z = spdyDataProvider != null ? spdyDataProvider.finished : true;
String[] mapToByteArray = mapToByteArray(spdyRequest.getHeaders());
w.lock();
try {
spdySession = spdyAgent.sessionMgr.get(spdyRequest.getAuthority());
} catch (Throwable unused) {
spdySession = null;
}
if (spdySession != null) {
spdySession.submitRequest(spdyRequest, spdyDataProvider, obj2, spdycb);
w.unlock();
return spdySession;
}
try {
SpdySession spdySession5 = new SpdySession(0, spdyAgent, spdyRequest.getAuthority(), sessionCb);
int putSpdyStreamCtx = spdySession5.putSpdyStreamCtx(new SpdyStreamContext(obj2, spdycb));
spduLog.Logi("tnet-jni", "index=" + putSpdyStreamCtx + " starttime=" + System.currentTimeMillis());
spduLog.Logi("tnet-jni", "[submitRequest] - Create session and send request: " + spdyRequest.getHost() + ":" + spdyRequest.getPort() + "/" + spdyRequest.getProxyIp() + ":" + spdyRequest.getProxyPort());
try {
if (spdyAgent.proxyUsername != null) {
try {
if (spdyAgent.proxyPassword != null) {
i2 = putSpdyStreamCtx;
spdySession2 = spdySession5;
submitRequest = submitRequest(spdyAgent.agentNativePtr, spdySession5, spdyRequest.getHost().getBytes(), (char) spdyRequest.getPort(), spdyRequest.getProxyIp().getBytes(), (char) spdyRequest.getProxyPort(), spdyAgent.proxyUsername.getBytes(), spdyAgent.proxyPassword.getBytes(), spdyRequest.getUrlPath().getBytes(), (byte) spdyRequest.getPriority(), mapToByteArray, bArr, z, obj, i2, 2, spdyRequest.getConnectionTimeoutMs(), spdyRequest.getRequestTimeoutMs(), spdyRequest.getRetryTimes());
spduLog.Logi("tnet-jni", "index=" + i2 + " calltime=" + System.currentTimeMillis());
i3 = (int) (submitRequest & (-1));
int i4 = (int) ((submitRequest >> 32) & (-1));
if (i3 == 0) {
spdySession3 = spdySession2;
spdySession3.setSessionNativePtr(i3);
this.sessionMgr.put(spdyRequest.getAuthority(), spdySession3);
this.sessionQueue.add(spdySession3);
} else {
if (i4 != 0) {
throw new SpdyErrorException("submit error: " + i4, i4);
}
spdySession3 = null;
}
w.unlock();
return spdySession3;
}
} catch (Throwable th) {
th = th;
w.unlock();
throw th;
}
}
if (i3 == 0) {
}
w.unlock();
return spdySession3;
} catch (Throwable th2) {
th = th2;
w.unlock();
throw th;
}
i2 = putSpdyStreamCtx;
spdySession2 = spdySession5;
spdyAgent = this;
submitRequest = submitRequest(spdyAgent.agentNativePtr, spdySession2, spdyRequest.getHost().getBytes(), (char) spdyRequest.getPort(), spdyRequest.getProxyIp().getBytes(), (char) spdyRequest.getProxyPort(), null, null, spdyRequest.getUrlPath().getBytes(), (byte) spdyRequest.getPriority(), mapToByteArray, bArr, z, obj, i2, 2, spdyRequest.getConnectionTimeoutMs(), spdyRequest.getRequestTimeoutMs(), spdyRequest.getRetryTimes());
spduLog.Logi("tnet-jni", "index=" + i2 + " calltime=" + System.currentTimeMillis());
i3 = (int) (submitRequest & (-1));
int i42 = (int) ((submitRequest >> 32) & (-1));
} catch (Throwable th3) {
th = th3;
}
} finally {
r.unlock();
}
}
private void agentIsOpen() {
if (this.closed.get()) {
throw new SpdyErrorException("SPDY_JNI_ERR_ASYNC_CLOSE", TnetStatusCode.TNET_JNI_ERR_ASYNC_CLOSE);
}
}
public void removeSession(SpdySession spdySession) {
w.lock();
try {
this.sessionQueue.remove(spdySession);
} finally {
w.unlock();
}
}
public int closeSession(int i) {
return closeSessionN(i);
}
public static String[] mapToByteArray(Map<String, String> map) {
if (map == null || map.size() <= 0) {
return null;
}
String[] strArr = new String[map.size() * 2];
int i = 0;
for (Map.Entry<String, String> entry : map.entrySet()) {
strArr[i] = entry.getKey();
strArr[i + 1] = entry.getValue();
i += 2;
}
return strArr;
}
static Map<String, List<String>> stringArrayToMap(String[] strArr) {
if (strArr == null) {
return null;
}
HashMap hashMap = new HashMap(5);
int i = 0;
while (true) {
int i2 = i + 2;
if (i2 > strArr.length) {
return hashMap;
}
if (strArr[i] == null) {
break;
}
int i3 = i + 1;
if (strArr[i3] == null) {
break;
}
List list = (List) hashMap.get(strArr[i]);
if (list == null) {
list = new ArrayList(1);
hashMap.put(strArr[i], list);
}
list.add(strArr[i3]);
i = i2;
}
}
public int setSessionKind(SpdySessionKind spdySessionKind) {
agentIsOpen();
try {
return setSessionKind(this.agentNativePtr, spdySessionKind.getint());
} catch (UnsatisfiedLinkError e) {
e.printStackTrace();
return -1;
}
}
public int setConnectTimeOut(int i) {
agentIsOpen();
try {
return setConTimeout(this.agentNativePtr, i);
} catch (UnsatisfiedLinkError e) {
e.printStackTrace();
return 0;
}
}
private void spdySessionConnectCB(SpdySession spdySession, SuperviseConnectInfo superviseConnectInfo) {
spduLog.Logi("tnet-jni", "[spdySessionConnectCB] - ");
if (spdySession == null) {
spduLog.Logi("tnet-jni", "[spdySessionConnectCB] - session is null");
} else if (spdySession.intenalcb == null) {
spduLog.Logi("tnet-jni", "[spdySessionConnectCB] - session.intenalcb is null");
} else {
spdySession.intenalcb.spdySessionConnectCB(spdySession, superviseConnectInfo);
}
}
private void spdyDataChunkRecvCB(SpdySession spdySession, boolean z, int i, byte[] bArr, int i2, int i3) {
spduLog.Logi("tnet-jni", "[spdyDataChunkRecvCB] - ");
long j = 4294967295L & i;
if (spdySession == null) {
spduLog.Logi("tnet-jni", "[spdyDataChunkRecvCB] - session is null");
} else if (spdySession.intenalcb == null) {
spduLog.Logi("tnet-jni", "[spdyDataChunkRecvCB] - session.intenalcb is null");
} else {
spdySession.intenalcb.spdyDataChunkRecvCB(spdySession, z, j, bArr, i2, i3);
}
}
private void spdyDataRecvCallback(SpdySession spdySession, boolean z, int i, int i2, int i3) {
spduLog.Logi("tnet-jni", "[spdyDataRecvCallback] - ");
long j = 4294967295L & i;
if (spdySession == null) {
spduLog.Logi("tnet-jni", "[spdyDataRecvCallback] - session is null");
} else if (spdySession.intenalcb == null) {
spduLog.Logi("tnet-jni", "[spdyDataRecvCallback] - session.intenalcb is null");
} else {
spdySession.intenalcb.spdyDataRecvCallback(spdySession, z, j, i2, i3);
}
}
private void spdyDataSendCallback(SpdySession spdySession, boolean z, int i, int i2, int i3) {
long j = 4294967295L & i;
if (spdySession == null) {
spduLog.Logi("tnet-jni", "[spdyDataSendCallback] - session is null");
} else if (spdySession.intenalcb == null) {
spduLog.Logi("tnet-jni", "[spdyDataSendCallback] - session.intenalcb is null");
} else {
spdySession.intenalcb.spdyDataSendCallback(spdySession, z, j, i2, i3);
}
}
private void spdyStreamCloseCallback(SpdySession spdySession, int i, int i2, int i3, SuperviseData superviseData) {
spduLog.Logi("tnet-jni", "[spdyStreamCloseCallback] - ");
long j = i & 4294967295L;
if (spdySession == null) {
spduLog.Logi("tnet-jni", "[spdyStreamCloseCallback] - session is null");
} else if (spdySession.intenalcb == null) {
spduLog.Logi("tnet-jni", "[spdyStreamCloseCallback] - session.intenalcb is null");
} else {
spdySession.intenalcb.spdyStreamCloseCallback(spdySession, j, i2, i3, superviseData);
}
}
private void spdyPingRecvCallback(SpdySession spdySession, int i, Object obj) {
spduLog.Logi("tnet-jni", "[spdyPingRecvCallback] - ");
long j = i & 4294967295L;
if (spdySession == null) {
spduLog.Logi("tnet-jni", "[spdyPingRecvCallback] - session is null");
} else if (spdySession.intenalcb == null) {
spduLog.Logi("tnet-jni", "[spdyPingRecvCallback] - session.intenalcb is null");
} else {
spdySession.intenalcb.spdyPingRecvCallback(spdySession, j, obj);
}
}
private void spdyCustomControlFrameRecvCallback(SpdySession spdySession, Object obj, int i, int i2, int i3, int i4, byte[] bArr) {
spduLog.Logi("tnet-jni", "[spdyCustomControlFrameRecvCallback] - ");
if (spdySession == null) {
spduLog.Logi("tnet-jni", "[spdyCustomControlFrameRecvCallback] - session is null");
} else if (spdySession.intenalcb == null) {
spduLog.Logi("tnet-jni", "[spdyCustomControlFrameRecvCallback] - session.intenalcb is null");
} else {
spdySession.intenalcb.spdyCustomControlFrameRecvCallback(spdySession, obj, i, i2, i3, i4, bArr);
}
}
private void spdyRequestRecvCallback(SpdySession spdySession, int i, int i2) {
long j = i & 4294967295L;
if (spdySession == null) {
spduLog.Logi("tnet-jni", "[spdyRequestRecvCallback] - session is null");
} else if (spdySession.intenalcb == null) {
spduLog.Logi("tnet-jni", "[spdyRequestRecvCallback] - session.intenalcb is null");
} else {
spdySession.intenalcb.spdyRequestRecvCallback(spdySession, j, i2);
}
}
private void spdyStreamResponseRecv(SpdySession spdySession, int i, String[] strArr, int i2) {
spduLog.Logi("tnet-jni", "[spdyStreamResponseRecv] - ");
Map<String, List<String>> stringArrayToMap = stringArrayToMap(strArr);
long j = i & 4294967295L;
if (spdySession == null) {
spduLog.Logi("tnet-jni", "[spdyStreamResponseRecv] - session is null");
} else if (spdySession.intenalcb == null) {
spduLog.Logi("tnet-jni", "[spdyStreamResponseRecv] - session.intenalcb is null");
} else {
spdySession.intenalcb.spdyOnStreamResponse(spdySession, j, stringArrayToMap, i2);
}
}
private void spdySessionCloseCallback(SpdySession spdySession, Object obj, SuperviseConnectInfo superviseConnectInfo, int i) {
spduLog.Logi("tnet-jni", "[spdySessionCloseCallback] - errorCode = " + i);
if (spdySession == null) {
spduLog.Logi("tnet-jni", "[spdySessionCloseCallback] - session is null");
} else if (spdySession.intenalcb == null) {
spduLog.Logi("tnet-jni", "[spdySessionCloseCallback] - session.intenalcb is null");
} else {
spdySession.intenalcb.spdySessionCloseCallback(spdySession, obj, superviseConnectInfo, i);
}
}
private void spdySessionFailedError(SpdySession spdySession, int i, Object obj) {
spduLog.Logi("tnet-jni", "[spdySessionFailedError] - ");
if (spdySession == null) {
spduLog.Logi("tnet-jni", "[spdySessionFailedError] - session is null");
} else if (spdySession.intenalcb == null) {
spduLog.Logi("tnet-jni", "[spdySessionFailedError] - session.intenalcb is null");
} else {
spdySession.intenalcb.spdySessionFailedError(spdySession, i, obj);
}
}
public int configLogFile(String str, int i, int i2) {
return configLogFileN(str, i, i2);
}
public int configLogFile(String str, int i, int i2, int i3) {
return configLogFileN(str, i, i2, i3);
}
public void logFileFlush() {
logFileFlushN();
}
public void logFileClose() {
logFileFlushN();
logFileCloseN();
}
public static void inspect(String str) {
inspectN(str);
}
}