QQ浏览器 v12.2.3.7053版本的 MD5 值为:8285ab3059e5c8b521a264dfbc5c3685
以下内容为反编译后的 CronetOkHttpURLConnection.java 源代码,内容仅作参考
package com.tencent.mtt.network.tbsnet;
import android.os.Bundle;
import android.util.Pair;
import android.webkit.ValueCallback;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.tencent.common.featuretoggle.FeatureToggle;
import com.tencent.common.http.HttpTimeRecord;
import com.tencent.common.http.MttRequestBase;
import com.tencent.common.threadpool.BrowserExecutorSupplier;
import com.tencent.common.threadpool.inter.IQBExecutorService;
import com.tencent.common.wup.WUPTask;
import com.tencent.common.wup.WUPTaskClient;
import com.tencent.mtt.AppInfoHolder;
import com.tencent.mtt.apkplugin.impl.IAPInjectService;
import com.tencent.mtt.browser.jsextension.open.IOpenJsApis;
import com.tencent.mtt.network.QBUrl;
import com.tencent.mtt.network.oksupport.QBOKConnection;
import com.tencent.tbs.common.internal.service.StatServerHolder;
import com.tencent.wup.BuildConfig;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;
import java.util.concurrent.Executor;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSocketFactory;
import org.chromium.net.CronetEngine;
import org.chromium.net.CronetException;
import org.chromium.net.ExperimentalUrlRequest;
import org.chromium.net.NetworkException;
import org.chromium.net.UrlRequest;
import org.chromium.net.UrlResponseInfo;
public class CronetOkHttpURLConnection extends QBOKConnection {
private static final String CONTENT_LENGTH = "Content-Length";
public static final int HTTP_BAD_REQUEST = 400;
private static final String TAG = CronetOkHttpURLConnection.class.getSimpleName();
private Boolean connected;
private long endTime;
boolean hasRequestHeaderAcceptEncoding;
boolean hasRequestHeaderRange;
private ValueCallback<Bundle> mAsyncCallBack;
int mConnectionTimeout;
private final CronetEngine mCronetEngine;
private IOException mException;
private boolean mHasResponseHeadersOrCompleted;
private CronetInputStream mInputStream;
private final MessageLoop mMessageLoop;
private boolean mOnRedirectCalled;
private CronetOutputStream mOutputStream;
QBUrl mQbUrl;
private Random mRandomGen;
private UrlRequest mRequest;
private final List<Pair<String, String>> mRequestHeaders;
private List<Map.Entry<String, String>> mResponseHeadersList;
private Map<String, List<String>> mResponseHeadersMap;
private UrlResponseInfo mResponseInfo;
private int mTrafficStatsTag;
private boolean mTrafficStatsTagSet;
private int mTrafficStatsUid;
private boolean mTrafficStatsUidSet;
private long receiveHeaderTime;
private long startTime;
boolean transparentGzip;
public class CronetUrlRequestCallback extends UrlRequest.Callback {
public CronetUrlRequestCallback() {
}
private void setResponseDataCompleted(IOException iOException) {
CronetOkHttpURLConnection.this.mException = iOException;
if (CronetOkHttpURLConnection.this.mInputStream != null) {
CronetOkHttpURLConnection.this.mInputStream.setResponseDataCompleted(iOException);
}
if (CronetOkHttpURLConnection.this.mOutputStream != null) {
CronetOkHttpURLConnection.this.mOutputStream.setRequestCompleted(iOException);
}
CronetOkHttpURLConnection.this.mHasResponseHeadersOrCompleted = true;
CronetOkHttpURLConnection.this.mMessageLoop.quit();
}
@Override
public void onCanceled(UrlRequest urlRequest, UrlResponseInfo urlResponseInfo) {
CronetOkHttpURLConnection.this.mResponseInfo = urlResponseInfo;
setResponseDataCompleted(new IOException("disconnect() called"));
if (CronetOkHttpURLConnection.this.mAsyncCallBack != null) {
Bundle bundle = new Bundle();
bundle.putString("caller", "onCanceled");
CronetOkHttpURLConnection.this.mAsyncCallBack.onReceiveValue(bundle);
}
CronetOkHttpURLConnection.this.uploadNetworkQualityToBeacon("cancel");
}
@Override
public void onFailed(UrlRequest urlRequest, UrlResponseInfo urlResponseInfo, CronetException cronetException) {
if (cronetException == null) {
throw new IllegalStateException("Exception cannot be null in onFailed.");
}
CronetOkHttpURLConnection.this.mResponseInfo = urlResponseInfo;
if (CronetOkHttpURLConnection.this.getBindObject() != null && (CronetOkHttpURLConnection.this.getBindObject() instanceof MttRequestBase)) {
MttRequestBase mttRequestBase = (MttRequestBase) CronetOkHttpURLConnection.this.getBindObject();
if (mttRequestBase.getSpanProxy() != null) {
mttRequestBase.getSpanProxy().addEvent("TBSNET_FAILED");
}
}
CronetOkHttpURLConnection.this.printDebugNetworkLogIfNeeded(urlResponseInfo, true, cronetException);
setResponseDataCompleted(cronetException);
if (CronetOkHttpURLConnection.this.mAsyncCallBack != null) {
Bundle bundle = new Bundle();
bundle.putString("caller", "onFailed");
if (cronetException != null && (cronetException instanceof NetworkException)) {
NetworkException networkException = (NetworkException) cronetException;
bundle.putInt("cronetErrorCode", networkException.getErrorCode());
bundle.putInt("cronetDetailErrorCode", networkException.getCronetInternalErrorCode());
}
CronetOkHttpURLConnection.this.mAsyncCallBack.onReceiveValue(bundle);
}
CronetOkHttpURLConnection.this.uploadNetworkQualityToBeacon("false");
}
@Override
public void onReadCompleted(UrlRequest urlRequest, UrlResponseInfo urlResponseInfo, ByteBuffer byteBuffer) {
CronetOkHttpURLConnection.this.mResponseInfo = urlResponseInfo;
CronetOkHttpURLConnection.this.mMessageLoop.quit();
}
@Override
public void onRedirectReceived(UrlRequest urlRequest, UrlResponseInfo urlResponseInfo, String str) {
CronetOkHttpURLConnection.this.mOnRedirectCalled = true;
try {
URL url = new URL(str);
boolean equals = url.getProtocol().equals(CronetOkHttpURLConnection.this.url.getProtocol());
if (CronetOkHttpURLConnection.this.instanceFollowRedirects) {
CronetOkHttpURLConnection.this.url = url;
}
if (CronetOkHttpURLConnection.this.instanceFollowRedirects && equals) {
CronetOkHttpURLConnection.this.mRequest.followRedirect();
return;
}
} catch (MalformedURLException unused) {
}
CronetOkHttpURLConnection.this.mResponseInfo = urlResponseInfo;
CronetOkHttpURLConnection.this.mRequest.cancel();
setResponseDataCompleted(null);
}
@Override
public void onResponseStarted(UrlRequest urlRequest, UrlResponseInfo urlResponseInfo) {
CronetOkHttpURLConnection.this.mResponseInfo = urlResponseInfo;
CronetOkHttpURLConnection.this.mHasResponseHeadersOrCompleted = true;
if (CronetOkHttpURLConnection.this.getBindObject() != null && (CronetOkHttpURLConnection.this.getBindObject() instanceof MttRequestBase)) {
MttRequestBase mttRequestBase = (MttRequestBase) CronetOkHttpURLConnection.this.getBindObject();
if (mttRequestBase.getSpanProxy() != null) {
mttRequestBase.getSpanProxy().addEvent("TBSNET_ONRESPONSE_START");
}
}
CronetOkHttpURLConnection.this.mMessageLoop.quit();
CronetOkHttpURLConnection.this.receiveHeaderTime = System.currentTimeMillis();
if (CronetOkHttpURLConnection.this.mAsyncCallBack != null) {
Bundle bundle = new Bundle();
bundle.putString("caller", "onResponseStarted");
CronetOkHttpURLConnection.this.mAsyncCallBack.onReceiveValue(bundle);
}
}
@Override
public void onSucceeded(UrlRequest urlRequest, UrlResponseInfo urlResponseInfo) {
CronetOkHttpURLConnection.this.mResponseInfo = urlResponseInfo;
if (CronetOkHttpURLConnection.this.getBindObject() != null && (CronetOkHttpURLConnection.this.getBindObject() instanceof MttRequestBase)) {
MttRequestBase mttRequestBase = (MttRequestBase) CronetOkHttpURLConnection.this.getBindObject();
if (mttRequestBase.getSpanProxy() != null) {
mttRequestBase.getSpanProxy().addEvent("TBSNET_SUCCESS");
}
}
setResponseDataCompleted(null);
CronetOkHttpURLConnection.this.uploadNetworkQualityToBeacon(IOpenJsApis.TRUE);
CronetOkHttpURLConnection.this.printDebugNetworkLogIfNeeded(urlResponseInfo, false, null);
}
}
public CronetOkHttpURLConnection(QBUrl qBUrl, CronetEngine cronetEngine) {
super(qBUrl.a());
this.connected = false;
this.mAsyncCallBack = null;
this.startTime = -1L;
this.endTime = -1L;
this.receiveHeaderTime = -1L;
this.mRandomGen = new Random();
this.transparentGzip = false;
this.hasRequestHeaderAcceptEncoding = false;
this.hasRequestHeaderRange = false;
this.mConnectionTimeout = 10000;
this.mQbUrl = qBUrl;
this.mCronetEngine = cronetEngine;
this.mMessageLoop = new MessageLoop();
this.mInputStream = new CronetInputStream(this);
this.mRequestHeaders = new ArrayList();
}
private void checkHasResponseHeaders() throws IOException {
if (!this.mHasResponseHeadersOrCompleted) {
throw new IllegalStateException("No response.");
}
IOException iOException = this.mException;
if (iOException != null) {
throw iOException;
}
if (this.mResponseInfo == null) {
throw new NullPointerException("Response info is null when there is no exception.");
}
}
private void checkRequestHeader() {
for (Pair<String, String> pair : this.mRequestHeaders) {
if (((String) pair.first).equalsIgnoreCase("Accept-Encoding")) {
this.hasRequestHeaderAcceptEncoding = true;
}
if (((String) pair.first).equalsIgnoreCase("Range")) {
this.hasRequestHeaderRange = true;
}
}
}
private void checkTransparentGzip() {
for (Map.Entry<String, String> entry : this.mResponseInfo.getAllHeadersAsList()) {
if (entry.getKey().equalsIgnoreCase("Content-Encoding") && entry.getValue().equalsIgnoreCase("gzip")) {
this.transparentGzip = true;
}
}
}
public void doUpload(String str) {
String str2 = "";
try {
HashMap<String, String> performanceMap = getPerformanceMap();
if (this.mResponseInfo == null || this.mResponseInfo.getUrl().startsWith("https://otheve.beacon.qq.com")) {
return;
}
performanceMap.put("url", this.mResponseInfo.getUrl());
performanceMap.put("success", str);
performanceMap.put(HiAnalyticsConstant.HaKey.BI_KEY_RESULT, "" + this.mResponseInfo.getHttpStatusCode());
performanceMap.put("contentLength", "" + this.mResponseInfo.getReceivedByteCount());
if (this.mException != null) {
str2 = this.mException.getMessage();
}
performanceMap.put("exceptionMsg", str2);
performanceMap.put("guid", AppInfoHolder.getAppInfoByID(AppInfoHolder.AppInfoID.APP_INFO_GUID));
performanceMap.put("qua2", AppInfoHolder.getAppInfoByID(AppInfoHolder.AppInfoID.APP_INFO_QUA2_3));
performanceMap.put("connectionType", "CronetOkHttpURLConnection");
StatServerHolder.statWithBeacon("MTT_NETWORK_QUALITY_STAT_BEACON", performanceMap);
} catch (Exception unused) {
}
}
private void executeInHighPriorityIfNeeded() {
((getBindObject() == null || !(getBindObject() instanceof MttRequestBase) || WUPTaskClient.mHighPriorityTaskMatcher == null || ((MttRequestBase) getBindObject()).getServerName() == null || ((MttRequestBase) getBindObject()).getFuncName() == null || !WUPTaskClient.mHighPriorityTaskMatcher.isHighPriorityTask(((MttRequestBase) getBindObject()).getServerName(), ((MttRequestBase) getBindObject()).getFuncName()) || !FeatureToggle.a(BuildConfig.BUG_TOGGLE_94180443)) ? BrowserExecutorSupplier.getInstance().getWupExecutor() : BrowserExecutorSupplier.getInstance().getHighProrityWupExecutor()).execute(getRunnable());
}
private int findRequestProperty(String str) {
for (int i = 0; i < this.mRequestHeaders.size(); i++) {
if (((String) this.mRequestHeaders.get(i).first).equalsIgnoreCase(str)) {
return i;
}
}
return -1;
}
private Map<String, List<String>> getAllHeaders() {
Map<String, List<String>> map = this.mResponseHeadersMap;
if (map != null) {
return map;
}
TreeMap treeMap = new TreeMap(String.CASE_INSENSITIVE_ORDER);
for (Map.Entry<String, String> entry : getAllHeadersAsList()) {
ArrayList arrayList = new ArrayList();
if (treeMap.containsKey(entry.getKey())) {
arrayList.addAll((Collection) treeMap.get(entry.getKey()));
}
arrayList.add(entry.getValue());
treeMap.put(entry.getKey(), Collections.unmodifiableList(arrayList));
}
this.mResponseHeadersMap = Collections.unmodifiableMap(treeMap);
return this.mResponseHeadersMap;
}
private List<Map.Entry<String, String>> getAllHeadersAsList() {
List<Map.Entry<String, String>> list = this.mResponseHeadersList;
if (list != null) {
return list;
}
checkTransparentGzip();
this.mResponseHeadersList = new ArrayList();
for (Map.Entry<String, String> entry : this.mResponseInfo.getAllHeadersAsList()) {
if ((!entry.getKey().equalsIgnoreCase("Content-Length") && !entry.getKey().equalsIgnoreCase("Content-Encoding")) || !this.transparentGzip || !this.hasRequestHeaderAcceptEncoding || this.hasRequestHeaderRange) {
if (!entry.getKey().equalsIgnoreCase("Content-Encoding")) {
this.mResponseHeadersList.add(new AbstractMap.SimpleImmutableEntry(entry));
}
}
}
this.mResponseHeadersList = Collections.unmodifiableList(this.mResponseHeadersList);
return this.mResponseHeadersList;
}
private Map.Entry<String, String> getHeaderFieldEntry(int i) {
try {
getResponse();
List<Map.Entry<String, String>> allHeadersAsList = getAllHeadersAsList();
if (i >= allHeadersAsList.size()) {
return null;
}
return allHeadersAsList.get(i);
} catch (IOException unused) {
return null;
}
}
private void getResponse() throws IOException {
CronetOutputStream cronetOutputStream = this.mOutputStream;
if (cronetOutputStream != null) {
cronetOutputStream.checkReceivedEnoughContent();
if (isChunkedUpload()) {
this.mOutputStream.close();
}
this.mOutputStream.setHasGetResponse();
}
if (!this.mHasResponseHeadersOrCompleted) {
startRequest();
if (this.mAsyncCallBack == null) {
this.mMessageLoop.loop(this.mConnectionTimeout + 1000);
}
}
checkHasResponseHeaders();
}
private Runnable getRunnable() {
return new Runnable() {
@Override
public void run() {
try {
if (CronetOkHttpURLConnection.this.getBindObject() != null && (CronetOkHttpURLConnection.this.getBindObject() instanceof MttRequestBase)) {
MttRequestBase mttRequestBase = (MttRequestBase) CronetOkHttpURLConnection.this.getBindObject();
if (mttRequestBase.getSpanProxy() != null) {
mttRequestBase.getSpanProxy().addEvent("TBSNET_START_LOOP");
}
}
CronetOkHttpURLConnection.this.mMessageLoop.loop(CronetOkHttpURLConnection.this.mConnectionTimeout);
} catch (Exception unused) {
}
}
};
}
private long getStreamingModeContentLength() {
long j = this.fixedContentLength;
try {
long j2 = getClass().getField("fixedContentLengthLong").getLong(this);
return j2 != -1 ? j2 : j;
} catch (IllegalAccessException | NoSuchFieldException unused) {
return j;
}
}
private boolean isChunkedUpload() {
return this.chunkLength > 0;
}
private void prepareMessageLoop() {
IQBExecutorService onTimeExecutor;
if (this.mAsyncCallBack != null) {
if (this.mQbUrl.d().equals("BlackListExecutor")) {
BrowserExecutorSupplier.getInstance().getBlackListExecutor().execute(getRunnable());
return;
}
if (this.mQbUrl.d().equals("NetworkExecutor")) {
onTimeExecutor = BrowserExecutorSupplier.getInstance().getNetworkExecutor();
} else {
if (!this.mQbUrl.d().equals(WUPTask.EMERGENCY_TASK)) {
if (this.mQbUrl.d().equals(WUPTask.BACKGROUND_TASK)) {
BrowserExecutorSupplier.forBackgroundTasks().execute(getRunnable());
return;
} else {
executeInHighPriorityIfNeeded();
return;
}
}
onTimeExecutor = BrowserExecutorSupplier.onTimeExecutor();
}
onTimeExecutor.execute(getRunnable());
}
}
private void prepareRequestHeaders(ExperimentalUrlRequest.Builder builder) throws IOException {
if (this.doOutput) {
if (this.method.equals("GET")) {
this.method = "POST";
}
CronetOutputStream cronetOutputStream = this.mOutputStream;
if (cronetOutputStream != null) {
builder.setUploadDataProvider(cronetOutputStream.getUploadDataProvider(), (Executor) this.mMessageLoop);
if (getRequestProperty("Content-Length") == null && !isChunkedUpload()) {
addRequestProperty("Content-Length", Long.toString(this.mOutputStream.getUploadDataProvider().getLength()));
}
this.mOutputStream.setConnected();
this.mOutputStream.setHasGetResponse();
} else if (getRequestProperty("Content-Length") == null) {
addRequestProperty("Content-Length", "0");
}
if (getRequestProperty("Content-Type") == null) {
addRequestProperty("Content-Type", "application/x-www-form-urlencoded");
}
}
}
public void printDebugNetworkLogIfNeeded(UrlResponseInfo urlResponseInfo, boolean z, CronetException cronetException) {
String str;
long j;
long j2;
long j3;
long j4;
if (HttpTimeRecord.isDebugMode || z || (getBindObject() != null && (getBindObject() instanceof MttRequestBase) && ((MttRequestBase) getBindObject()).getIsWupRequest())) {
List<Pair<String, String>> list = this.mRequestHeaders;
UrlResponseInfo urlResponseInfo2 = this.mResponseInfo;
String str2 = IAPInjectService.EP_NULL;
long j5 = -1;
if (urlResponseInfo2 != null) {
long j6 = this.endTime - (-1);
long j7 = (-1) - this.startTime;
j2 = (urlResponseInfo2.getDnsEndTime() - this.mResponseInfo.getDnsStartTime()) / 1000;
j3 = (this.mResponseInfo.getConnectEndTime() - this.mResponseInfo.getConnectStartTime()) / 1000;
j4 = this.endTime - this.startTime;
if (this.mResponseInfo.getAllHeaders() != null) {
str2 = this.mResponseInfo.getAllHeaders().toString();
}
str = str2;
j = j7;
j5 = j6;
} else {
str = IAPInjectService.EP_NULL;
j = -1;
j2 = -1;
j3 = -1;
j4 = -1;
}
String str3 = TAG;
StringBuilder sb = new StringBuilder();
sb.append("CronetOkHttpURLConnection onSucceeded url=");
sb.append(this.url.toString());
sb.append(" uniqueId=");
sb.append(getUniqueIdFromBindObject());
sb.append(" receive_body_time=");
sb.append(j5);
sb.append(" receive_header_time=");
sb.append(j);
sb.append(" dns_time=");
sb.append(j2);
sb.append(" connect_time=");
sb.append(j3);
sb.append(" network_total_time=");
sb.append(j4);
sb.append(" requestHeader=");
sb.append(list.toString());
sb.append(" responseHeader=");
sb.append(str);
String str4 = "";
if (z) {
str4 = "" + cronetException.getMessage();
}
sb.append(str4);
TbsNetLiveLogger.error(str3, sb.toString());
}
}
private final void setRequestPropertyInternal(String str, String str2, boolean z) {
if (this.connected.booleanValue()) {
throw new IllegalStateException("Cannot modify request property after connection is made.");
}
int findRequestProperty = findRequestProperty(str);
if (findRequestProperty >= 0) {
if (!z) {
throw new UnsupportedOperationException("Cannot add multiple headers of the same key, " + str + ". crbug.com/432719.");
}
this.mRequestHeaders.remove(findRequestProperty);
}
this.mRequestHeaders.add(Pair.create(str, str2));
}
private void startRequest() throws IOException {
System.currentTimeMillis();
if (this.connected.booleanValue()) {
return;
}
if (getBindObject() != null && (getBindObject() instanceof MttRequestBase)) {
MttRequestBase mttRequestBase = (MttRequestBase) getBindObject();
if (mttRequestBase.getSpanProxy() != null) {
mttRequestBase.getSpanProxy().addEvent("TBSNET_START");
}
}
ExperimentalUrlRequest.Builder builder = (ExperimentalUrlRequest.Builder) this.mCronetEngine.newUrlRequestBuilder(getURL().toString(), new CronetUrlRequestCallback(), this.mMessageLoop);
prepareRequestHeaders(builder);
for (Pair<String, String> pair : this.mRequestHeaders) {
if (!((String) pair.first).equalsIgnoreCase("Accept-Encoding")) {
builder.addHeader((String) pair.first, (String) pair.second);
}
}
checkRequestHeader();
if (!getUseCaches()) {
builder.disableCache();
}
builder.setHttpMethod(this.method);
if (this.mTrafficStatsTagSet) {
builder.setTrafficStatsTag(this.mTrafficStatsTag);
}
if (this.mTrafficStatsUidSet) {
builder.setTrafficStatsUid(this.mTrafficStatsUid);
}
this.mRequest = builder.build();
this.mRequest.SetConnectionTimeout(this.mConnectionTimeout);
this.mRequest.start();
this.startTime = System.currentTimeMillis();
this.connected = true;
prepareMessageLoop();
}
public void uploadNetworkQualityToBeacon(final String str) {
this.endTime = System.currentTimeMillis();
if (this.mRandomGen.nextInt(100) >= 5 || this.mResponseInfo == null) {
return;
}
BrowserExecutorSupplier.postForIoTasks(new BrowserExecutorSupplier.BackgroundRunable() {
@Override
public void doRun() {
CronetOkHttpURLConnection.this.doUpload(str);
}
});
}
@Override
public final void addRequestProperty(String str, String str2) {
setRequestPropertyInternal(str, str2, false);
}
@Override
public void cancel() {
if (this.connected.booleanValue()) {
this.mRequest.cancel();
}
}
public void connect() throws IOException {
getOutputStream();
startRequest();
}
public void disconnect() {
if (this.connected.booleanValue()) {
this.mRequest.cancel();
}
}
@Override
public void execute() throws IOException {
if (getBindObject() != null && (getBindObject() instanceof MttRequestBase)) {
((MttRequestBase) getBindObject()).setIsTbsNetRequest(true);
}
connect();
}
@Override
public void executeAsync(ValueCallback<Bundle> valueCallback) throws IOException {
if (getBindObject() != null && (getBindObject() instanceof MttRequestBase)) {
((MttRequestBase) getBindObject()).setIsTbsNetRequest(true);
}
this.mAsyncCallBack = valueCallback;
connect();
}
@Override
public InputStream getErrorStream() {
try {
getResponse();
if (this.mResponseInfo.getHttpStatusCode() >= 400) {
return this.mInputStream;
}
return null;
} catch (IOException unused) {
return null;
}
}
@Override
public final String getHeaderField(int i) {
Map.Entry<String, String> headerFieldEntry = getHeaderFieldEntry(i);
if (headerFieldEntry == null) {
return null;
}
return headerFieldEntry.getValue();
}
@Override
public final String getHeaderField(String str) {
try {
getResponse();
Map<String, List<String>> allHeaders = getAllHeaders();
if (!allHeaders.containsKey(str)) {
return null;
}
return allHeaders.get(str).get(r4.size() - 1);
} catch (IOException unused) {
return null;
}
}
@Override
public final String getHeaderFieldKey(int i) {
Map.Entry<String, String> headerFieldEntry = getHeaderFieldEntry(i);
if (headerFieldEntry == null) {
return null;
}
return headerFieldEntry.getKey();
}
@Override
public Map<String, List<String>> getHeaderFields() {
try {
getResponse();
return getAllHeaders();
} catch (IOException unused) {
return Collections.emptyMap();
}
}
@Override
public HostnameVerifier getHostnameVerifier() {
return null;
}
@Override
public InputStream getInputStream() throws IOException {
getResponse();
if (!this.instanceFollowRedirects && this.mOnRedirectCalled) {
throw new IOException("Cannot read response body of a redirect.");
}
if (this.mResponseInfo.getHttpStatusCode() < 400) {
return this.mInputStream;
}
throw new FileNotFoundException(this.url.toString());
}
public void getMoreData(ByteBuffer byteBuffer) throws IOException {
this.mRequest.read(byteBuffer);
this.mMessageLoop.loop(getReadTimeout());
}
@Override
public OutputStream getOutputStream() throws IOException {
if (this.mOutputStream == null && this.doOutput) {
if (this.connected.booleanValue()) {
throw new ProtocolException("Cannot write to OutputStream after receiving response.");
}
if (isChunkedUpload()) {
this.mOutputStream = new CronetChunkedOutputStream(this.chunkLength, this.mMessageLoop);
} else {
long streamingModeContentLength = getStreamingModeContentLength();
if (streamingModeContentLength != -1) {
this.mOutputStream = new CronetFixedModeOutputStream(streamingModeContentLength, this.mMessageLoop);
} else {
String requestProperty = getRequestProperty("Content-Length");
if (requestProperty == null) {
this.mOutputStream = new CronetBufferedOutputStream();
} else {
this.mOutputStream = new CronetBufferedOutputStream(Long.parseLong(requestProperty));
}
}
}
startRequest();
}
return this.mOutputStream;
}
@Override
public HashMap<String, String> getPerformanceMap() {
HashMap<String, String> hashMap = new HashMap<>();
if (this.mResponseInfo != null) {
hashMap.put("receive_body", "" + (this.endTime - this.receiveHeaderTime));
hashMap.put("receive_header", "" + (this.receiveHeaderTime - this.startTime));
hashMap.put("dns", "" + ((this.mResponseInfo.getDnsEndTime() - this.mResponseInfo.getDnsStartTime()) / 1000));
hashMap.put("connect", "" + ((this.mResponseInfo.getConnectEndTime() - this.mResponseInfo.getConnectStartTime()) / 1000));
hashMap.put("isReuse", "" + this.mResponseInfo.isSocketReuse());
hashMap.put("network_total", "" + (this.endTime - this.startTime));
}
return hashMap;
}
@Override
public Map<String, List<String>> getRequestProperties() {
if (this.connected.booleanValue()) {
throw new IllegalStateException("Cannot access request headers after connection is set.");
}
TreeMap treeMap = new TreeMap(String.CASE_INSENSITIVE_ORDER);
for (Pair<String, String> pair : this.mRequestHeaders) {
if (treeMap.containsKey(pair.first)) {
throw new IllegalStateException("Should not have multiple values.");
}
ArrayList arrayList = new ArrayList();
arrayList.add(pair.second);
treeMap.put(pair.first, Collections.unmodifiableList(arrayList));
}
return Collections.unmodifiableMap(treeMap);
}
@Override
public String getRequestProperty(String str) {
int findRequestProperty = findRequestProperty(str);
if (findRequestProperty >= 0) {
return (String) this.mRequestHeaders.get(findRequestProperty).second;
}
return null;
}
@Override
public int getResponseCode() throws IOException {
getResponse();
return this.mResponseInfo.getHttpStatusCode();
}
@Override
public String getResponseMessage() throws IOException {
getResponse();
return this.mResponseInfo.getHttpStatusText();
}
@Override
public SSLSocketFactory getSSLSocketFactory() {
return null;
}
public String getUniqueIdFromBindObject() {
StringBuilder sb = new StringBuilder();
sb.append("");
sb.append((getBindObject() == null || !(getBindObject() instanceof MttRequestBase)) ? "-1" : Integer.valueOf(((MttRequestBase) getBindObject()).getUniqueId()));
return sb.toString();
}
@Override
public void setConnectTimeout(int i) {
this.mConnectionTimeout = i;
}
@Override
public void setHostnameVerifier(HostnameVerifier hostnameVerifier) {
}
@Override
public final void setRequestProperty(String str, String str2) {
setRequestPropertyInternal(str, str2, true);
}
@Override
public void setSSLSocketFactory(SSLSocketFactory sSLSocketFactory) {
}
public void setTrafficStatsTag(int i) {
if (this.connected.booleanValue()) {
throw new IllegalStateException("Cannot modify traffic stats tag after connection is made.");
}
this.mTrafficStatsTagSet = true;
this.mTrafficStatsTag = i;
}
public void setTrafficStatsUid(int i) {
if (this.connected.booleanValue()) {
throw new IllegalStateException("Cannot modify traffic stats UID after connection is made.");
}
this.mTrafficStatsUidSet = true;
this.mTrafficStatsUid = i;
}
@Override
public boolean usingProxy() {
return false;
}
}