QQ浏览器 v12.2.3.7053版本的 MD5 值为:8285ab3059e5c8b521a264dfbc5c3685
以下内容为反编译后的 QueenHandler.java 源代码,内容仅作参考
package com.tencent.mtt.network.queen;
import android.text.TextUtils;
import android.webkit.ValueCallback;
import com.tencent.basesupport.FLogger;
import com.tencent.common.http.FreeFlow;
import com.tencent.common.http.HttpHeader;
import com.tencent.common.http.QueenConfig;
import com.tencent.common.threadpool.BrowserExecutorSupplier;
import com.tencent.mtt.AppInfoHolder;
import com.tencent.mtt.network.QBDNS;
import com.tencent.mtt.network.QBNetworkInfo;
import com.tencent.mtt.network.http.DnsUtil;
import com.tencent.mtt.network.http.QBCode;
import com.tencent.mtt.network.http.QBHttpClientHandler;
import com.tencent.mtt.network.queen.QueenIPList;
import com.tencent.mtt.network.tbsnet.TbsNetLiveLogger;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.util.ArrayList;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
import okhttp3.Headers;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.internal.Util;
import org.chromium.net.CronetEngine;
import org.chromium.net.UrlRequest;
public class QueenHandler implements QBHttpClientHandler {
private static volatile QueenHandler f68510d;
private static Object e = new Object();
static Executor f68509a = BrowserExecutorSupplier.getInstance().newFixedThreadPool(2, "QueenHandler");
private AtomicBoolean f68512c = new AtomicBoolean(false);
private String f = "";
private String g = "";
private String h = "";
AtomicBoolean f68511b = new AtomicBoolean(false);
private long i = 0;
static class UrlConverter implements ValueCallback<String>, Runnable {
Object f68513a;
String f68514b;
String f68515c;
private boolean f68516d;
private void a() {
synchronized (this.f68513a) {
if (this.f68516d) {
return;
}
synchronized (this.f68513a) {
this.f68516d = true;
this.f68513a.notifyAll();
}
}
}
@Override
public void onReceiveValue(String str) {
this.f68515c = str;
a();
}
@Override
public void run() {
FreeFlow.convertUrl(this.f68514b, this);
}
}
public static QueenHandler a() {
if (f68510d != null) {
return f68510d;
}
synchronized (e) {
if (f68510d == null) {
f68510d = new QueenHandler();
}
}
return f68510d;
}
private void a(String str, String str2) {
TbsNetLiveLogger.error("QueenHandler", str2 + " request=" + str);
}
private void a(UrlRequest urlRequest, KingCardRequest kingCardRequest, CronetEngine cronetEngine, String str) {
String str2;
if (!this.f68512c.get() && this.f68512c.compareAndSet(false, true)) {
cronetEngine.setQHeaders(new String[]{HttpHeader.REQ.QGUID, HttpHeader.REQ.QUA2, HttpHeader.REQ.Q_QIMEI, HttpHeader.REQ.QIMEI36, HttpHeader.REQ.QAUTH}, new String[]{AppInfoHolder.getAppInfoByID(AppInfoHolder.AppInfoID.APP_INFO_GUID), AppInfoHolder.getAppInfoByID(AppInfoHolder.AppInfoID.APP_INFO_QUA2_3), AppInfoHolder.getAppInfoByID(AppInfoHolder.AppInfoID.APP_INFO_QIMEI), AppInfoHolder.getAppInfoByID(AppInfoHolder.AppInfoID.APP_INFO_QIMEI36_FORHTTPHEADER), AppInfoHolder.getAppInfoByID(AppInfoHolder.AppInfoID.APP_INFO_QAUTH)});
}
if (a(str)) {
str2 = this.f;
} else {
urlRequest.setHttpDown();
str2 = this.g;
}
kingCardRequest.a(str2);
kingCardRequest.a(true);
}
private boolean a(KingCardRequest kingCardRequest) {
if (kingCardRequest.i() == null || kingCardRequest.i() == Proxy.NO_PROXY) {
return false;
}
kingCardRequest.a(false);
if (kingCardRequest.c() != 0) {
return true;
}
kingCardRequest.a(10);
return true;
}
private boolean a(KingCardRequest kingCardRequest, String str, String str2) {
String str3;
if (b(kingCardRequest)) {
str3 = "QueueProxyNotValid";
} else {
kingCardRequest.b(true);
if (a(kingCardRequest)) {
str3 = "ProxyNotValid";
} else {
if (!b(str)) {
return false;
}
kingCardRequest.a(false);
if (kingCardRequest.c() == 0) {
kingCardRequest.a(9);
}
str3 = "isLocalHost";
}
}
a(str2, str3);
return true;
}
private boolean a(KingCardRequest kingCardRequest, String str, String str2, QueenInfoProvider queenInfoProvider) {
if (!queenInfoProvider.isInWhiteList(str2) || !b(kingCardRequest, str, DnsUtil.getIP(str2, QBDNS.a()))) {
return false;
}
a(str, "checkIpDirectNotValid, errorCode=" + kingCardRequest.c());
return true;
}
private boolean a(KingCardRequest kingCardRequest, String str, boolean z) {
if (!z) {
return false;
}
FLogger.d("QueenHandler", "direct url: " + str);
kingCardRequest.a(false);
if (kingCardRequest.c() != 0) {
return true;
}
kingCardRequest.a(4);
return true;
}
private boolean a(KingCardRequest kingCardRequest, CronetEngine cronetEngine, String str) {
if (!TextUtils.isEmpty(this.f) && !TextUtils.isEmpty(this.g)) {
cronetEngine.setHttpsAndDownProxyAddress(this.f, this.g);
return false;
}
kingCardRequest.a(false);
if (kingCardRequest.c() == 0) {
kingCardRequest.a(6);
}
a(str, "queenProxy is null");
return true;
}
private boolean a(String str, String str2, String str3, String str4) {
if (str3 != null && !str3.isEmpty() && !str.isEmpty() && !str2.isEmpty() && !str4.isEmpty()) {
return false;
}
a(str, String.format("key or url empty, key = %s, url = %s, request.url.host = %s,requestId = %s", str3, str, str2, str4));
return true;
}
private boolean b(KingCardRequest kingCardRequest) {
if (kingCardRequest.e() && isQueenProxyEnable()) {
return false;
}
kingCardRequest.a(false);
kingCardRequest.b(false);
if (kingCardRequest.c() == 0) {
kingCardRequest.a(1);
}
return true;
}
private boolean b(KingCardRequest kingCardRequest, String str, String str2) {
if (!QueenDirectCache.a().b(str2)) {
return false;
}
FLogger.d("QueenHandler", "direct ip: " + str2 + " - " + str);
kingCardRequest.a(false);
if (kingCardRequest.c() != 0) {
return true;
}
kingCardRequest.a(5);
return true;
}
private boolean b(String str) {
return str.startsWith("127.0.0.1") || str.startsWith("localhost");
}
private boolean c(KingCardRequest kingCardRequest, String str, String str2) {
if (!TextUtils.isEmpty(str) && !TextUtils.isEmpty(str2)) {
return false;
}
kingCardRequest.a(false);
if (kingCardRequest.c() != 0) {
return true;
}
kingCardRequest.a(7);
return true;
}
public String a(boolean z) {
ArrayList<String> ipList = QueenConfig.getIpList(z);
return (ipList == null || ipList.size() < 1) ? "" : ipList.get(0);
}
public String a(byte[] bArr) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(bArr[0] & 255);
stringBuffer.append('.');
stringBuffer.append(bArr[1] & 255);
stringBuffer.append('.');
stringBuffer.append(bArr[2] & 255);
stringBuffer.append('.');
stringBuffer.append(bArr[3] & 255);
return stringBuffer.toString();
}
boolean a(String str) {
return str.regionMatches(true, Util.skipLeadingAsciiWhitespace(str, 0, str.length()), "https:", 0, 6);
}
public boolean a(UrlRequest urlRequest, URL url, KingCardRequest kingCardRequest, CronetEngine cronetEngine) {
StringBuilder sb;
String url2 = url.toString();
String host = url.getHost();
if (a(kingCardRequest, host, url.toString())) {
return false;
}
QueenInfoProvider b2 = b();
if (a(kingCardRequest, url2, b2.isUrlDirect(url2))) {
sb = new StringBuilder();
sb.append("handleDirectUrl, errorCode=");
sb.append(kingCardRequest.c());
} else {
if (a(kingCardRequest, url2, host, b2)) {
return false;
}
String c2 = c();
FLogger.d("QueenHandler", "getToken: " + c2 + " [" + url2 + "]");
String qkey = b().getQkey();
String valueOf = String.valueOf(System.currentTimeMillis());
String appInfoByID = AppInfoHolder.getAppInfoByID(AppInfoHolder.AppInfoID.APP_INFO_GUID);
if (a(url2, host, qkey, valueOf)) {
return false;
}
String a2 = QueenQKeyBuilder.a().a(b().getHttpInfoEncrypt(appInfoByID, host, url2, valueOf), qkey);
FLogger.d("QueenHandler", "QKeyHeader-Value: " + a2);
if (!c(kingCardRequest, c2, a2)) {
if (!c2.equals(this.h)) {
this.h = c2;
cronetEngine.setKingCardToken(c2);
}
String a3 = a(false);
String a4 = a(true);
if (!this.g.equals(a3) || !this.f.equals(a4)) {
this.g = a3;
this.f = a4;
if (a(kingCardRequest, cronetEngine, url2)) {
return false;
}
}
a(urlRequest, kingCardRequest, cronetEngine, url2);
return true;
}
sb = new StringBuilder();
sb.append("token or key valid, token=");
sb.append(c2);
sb.append(", qkeyValue=");
sb.append(a2);
}
a(url2, sb.toString());
return false;
}
public QueenInfoProvider b() {
return QueenInfoProvider.PROXY.get();
}
String c() {
QueenInfoProvider b2 = b();
String token = b2.getToken();
if (!TextUtils.isEmpty(token)) {
return token;
}
d();
if (!this.f68511b.compareAndSet(false, true)) {
return token;
}
FLogger.d("QueenHandler", "WAIT TOKEN...");
try {
Thread.sleep(3000L);
} catch (InterruptedException unused) {
}
return b2.getToken();
}
public void d() {
long currentTimeMillis = System.currentTimeMillis();
if (Math.abs(currentTimeMillis - this.i) < 5000) {
return;
}
this.i = currentTimeMillis;
b().refreshToken();
}
@Override
public boolean isQueenProxyEnable() {
if (b().isProxySwitchEnable()) {
return true;
}
return QBNetworkInfo.isQueenEnable();
}
@Override
public boolean needRetry(int i, Request request, KingCardRequest kingCardRequest) {
if (!kingCardRequest.e() || kingCardRequest.h() == null) {
return false;
}
switch (i) {
case 820:
case 821:
kingCardRequest.a(false);
kingCardRequest.b(i);
kingCardRequest.a(7);
return true;
case QBCode.HttpCode.QUEEN_HTTP_IP_DIRECT:
kingCardRequest.a(false);
kingCardRequest.b(i);
kingCardRequest.a(2);
String header = request.header("Q-DnsIp");
if (!TextUtils.isEmpty(header)) {
QueenDirectCache.a().a(header);
}
return true;
case QBCode.HttpCode.QUEEN_HTTP_RETRY:
kingCardRequest.b(i);
if (kingCardRequest.f() >= 3) {
kingCardRequest.a(false);
kingCardRequest.a(8);
} else {
kingCardRequest.c(kingCardRequest.f() + 1);
}
return true;
case QBCode.HttpCode.QUEEN_HTTP_FORCE_DIRECT:
kingCardRequest.a(false);
kingCardRequest.b(i);
kingCardRequest.a(3);
return true;
default:
return false;
}
}
@Override
public void onGetResponse(KingCardRequest kingCardRequest, Request request, Response response, InetAddress inetAddress) {
if (kingCardRequest.e() && isQueenProxyEnable()) {
QueenReporter.a(kingCardRequest, request, response, inetAddress != null ? a(inetAddress.getAddress()) : null);
}
}
@Override
public void onInputStreamException(Request request, Exception exc) {
FLogger.d("QueenHandler", "onInputStreamException: " + exc + ", request: " + request);
if (request != null) {
if (((exc instanceof SocketTimeoutException) || (exc instanceof SocketException)) && isQueenProxyEnable()) {
if (request.isHttps()) {
QueenIPList.b();
} else {
QueenIPList.a();
}
}
}
}
@Override
public Request prepareAndTransformRequest(OkHttpClient okHttpClient, Request request, KingCardRequest kingCardRequest) {
String str = null;
if (request == null) {
TbsNetLiveLogger.error("QueenHandler", "request == null");
return null;
}
String httpUrl = request.url().toString();
String host = request.url().host();
if (a(kingCardRequest, host, request.url().url().toString())) {
return request;
}
QueenInfoProvider b2 = b();
if (a(kingCardRequest, httpUrl, b2.isUrlDirect(httpUrl))) {
a(request.url().url().toString(), "handleDirectUrl errorcode=" + kingCardRequest.c());
return request;
}
if (b2.isInWhiteList(host)) {
str = DnsUtil.getIP(host, okHttpClient.dns());
if (b(kingCardRequest, httpUrl, str)) {
a(request.url().url().toString(), "checkIpDirectNotValid errorcode=" + kingCardRequest.c());
return request;
}
}
String c2 = c();
FLogger.d("QueenHandler", "getToken: " + c2 + " [" + httpUrl + "]");
String qkey = b().getQkey();
String valueOf = String.valueOf(System.currentTimeMillis());
String appInfoByID = AppInfoHolder.getAppInfoByID(AppInfoHolder.AppInfoID.APP_INFO_GUID);
if (a(httpUrl, request.url().host(), qkey, valueOf)) {
return request;
}
String a2 = QueenQKeyBuilder.a().a(b().getHttpInfoEncrypt(appInfoByID, request.url().host(), httpUrl, valueOf), qkey);
FLogger.d("QueenHandler", "QKeyHeader-Value: " + a2);
if (c(kingCardRequest, c2, a2)) {
a(request.url().url().toString(), "token or key valid token=" + c2 + ", qkeyValue=" + a2);
return request;
}
QueenIPList.QueenProxy a3 = QueenIPList.a(request.isHttps());
if (a3 == null) {
kingCardRequest.a(false);
if (kingCardRequest.c() == 0) {
kingCardRequest.a(6);
}
a(request.url().url().toString(), "queenProxy is null");
return request;
}
kingCardRequest.a(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(a3.f68525a, a3.f68526b)));
Headers a4 = new QueenHeaderBuilder().a(request.headers().newBuilder()).d(c2).c(valueOf).b(a2).a(kingCardRequest.a()).a(request.isHttps()).a(kingCardRequest.f()).e(str).a();
String str2 = a4.get("Proxy-Authorization");
if (!TextUtils.isEmpty(str2)) {
kingCardRequest.b(str2);
}
Request build = request.newBuilder().headers(a4).build();
kingCardRequest.a(true);
return build;
}
}