手机管家 v6.0.0版本的 MD5 值为:bf0bca2cb03f766137fe9ecf7383a634
以下内容为反编译后的 k.java 源代码,内容仅作参考
package tmsdk.common.internal.utils;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Pair;
import com.tencent.feedback.eup.BuglyBroadcastRecevier;
import com.tencent.kingkong.database.SQLiteDatabase;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ProtocolException;
import java.net.Proxy;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.zip.InflaterInputStream;
import org.apache.http.client.ClientProtocolException;
import tcs.ae;
import tcs.anr;
import tcs.aua;
import tcs.ke;
import tcs.qh;
import tcs.qi;
import tcs.qn;
import tcs.tz;
import tcs.uc;
import tcs.uh;
import tmsdk.common.TMSDKContext;
public final class k {
private static volatile String adr = null;
public static final String bQc = "GET";
public static final String bQd = "POST";
public static final String cFX = "dnc";
private String aOm;
private int bJa;
private String bPY;
private HttpURLConnection bQh;
private byte[] bQi;
private boolean bQs;
private boolean bQt;
private static volatile boolean bQu = false;
private static volatile String bQv = null;
private static volatile boolean bQw = false;
private static volatile boolean bQx = false;
private static volatile long bQy = 0;
private static volatile long cFY = 0;
private static Object cFZ = new Object();
private static ArrayList<Pair<Integer, Long>> cMR = new ArrayList<>();
private String bQg = "GET";
private int bQj = -1;
private Hashtable<String, String> bQk = new Hashtable<>(0);
private boolean bQl = false;
private boolean bQm = true;
private byte bQn = 0;
private byte bQo = 0;
private byte bQp = 0;
private int bQq = ke.YP;
private int bQr = ke.YP;
private boolean cFW = true;
private k(String str) {
this.aOm = str;
RV();
aua.j("HttpConnection", "initConnection requestUrl|" + str);
}
public static void RV() {
t tVar = new t("wup");
cFY = tVar.getLong(cFX, 0L);
adr = tVar.getString("cn_t_a", SQLiteDatabase.KeyEmpty);
if (!TextUtils.isEmpty(adr)) {
for (String str : adr.split("\\|")) {
if (!TextUtils.isEmpty(str)) {
String[] split = str.split(",");
try {
synchronized (cMR) {
if (cMR.size() <= 4) {
cMR.add(new Pair<>(Integer.valueOf(split[0]), Long.valueOf(split[1])));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
public static void bm(long j) {
cFY = System.currentTimeMillis() + j;
new t("wup").a(cFX, cFY, true);
}
public static boolean RW() {
synchronized (cFZ) {
long currentTimeMillis = System.currentTimeMillis();
return !(((cFY - currentTimeMillis) > 5184000L ? 1 : ((cFY - currentTimeMillis) == 5184000L ? 0 : -1)) > 0) && (((cFY - currentTimeMillis) > 0L ? 1 : ((cFY - currentTimeMillis) == 0L ? 0 : -1)) >= 0);
}
}
public static ArrayList<Pair<Integer, Long>> br() {
return cMR;
}
public static void XA() {
synchronized (cMR) {
adr = SQLiteDatabase.KeyEmpty;
new t("wup").b("cn_t_a", adr, true);
cMR.clear();
}
}
public static k iz(String str) throws qh {
return s(str, true);
}
public static k s(String str, boolean z) throws qh {
RV();
if (!tz.KD() && Thread.currentThread().getId() == Looper.getMainLooper().getThread().getId()) {
throw new qi();
}
if (str == null || str.length() == 0) {
throw new qh(-1000, "url is null!");
}
k kVar = new k(str);
kVar.bQs = false;
kVar.cFW = z;
ae KA = tz.KA();
if (ae.bu == KA) {
throw new qh(-1052, "no connecition!");
}
kVar.a(kVar.aOm, KA);
return kVar;
}
public static k a(k kVar) throws qh {
RV();
ae KA = tz.KA();
k kVar2 = new k(kVar.Hi());
kVar2.bQs = false;
if (ae.bu == KA) {
throw new qh(-1052, "no connection!");
}
kVar2.a(kVar2.aOm, KA);
kVar2.setRequestMethod(kVar.getRequestMethod());
kVar2.E(kVar.Hc());
kVar2.a(kVar.Hj());
return kVar2;
}
private void a(String str, ae aeVar) throws qh {
try {
getHostAddress();
if (ae.bu != aeVar) {
if (ae.bA == aeVar) {
Proxy proxy = new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(tz.KC(), tz.Eg()));
System.currentTimeMillis();
this.bQh = (HttpURLConnection) new URL(str).openConnection(proxy);
System.currentTimeMillis();
this.bQl = true;
return;
}
if (this.cFW && ae.by == aeVar && "com.tencent.qqpimsecure".equals(TMSDKContext.getApplicaionContext().getPackageName())) {
String ssid = uh.getSSID();
if (bQv == null || !bQv.equals(ssid) || (System.currentTimeMillis() - bQy > anr.dZK && !bQw)) {
bQu = false;
bQw = true;
bQv = ssid;
uh.a(new a());
} else if (bQu && !bQw) {
bQw = true;
uh.a(new a());
}
bQy = System.currentTimeMillis();
}
System.currentTimeMillis();
this.bQh = (HttpURLConnection) new URL(str).openConnection();
System.currentTimeMillis();
this.bQl = false;
this.bQh.setReadTimeout(this.bQr);
this.bQh.setConnectTimeout(this.bQq);
}
} catch (IOException e) {
throw new qh(-1056, "IOException : " + e.getMessage());
} catch (IllegalArgumentException e2) {
throw new qh(-1057, "IllegalArgumentException : " + e2.getMessage());
} catch (SecurityException e3) {
throw new qh(-1058, "SecurityException: " + e3.getMessage());
} catch (UnsupportedOperationException e4) {
throw new qh(-1059, "UnsupportedOperationException: " + e4.getMessage());
} catch (qn e5) {
}
}
public static k a(String str, boolean z, String str2, int i) throws qh {
return a(str, z, str2, i, true);
}
public static k a(String str, boolean z, String str2, int i, boolean z2) throws qh {
RV();
if (!tz.KD() && Thread.currentThread().getId() == Looper.getMainLooper().getThread().getId()) {
throw new qi();
}
if (str == null || str.length() == 0) {
throw new qh(-1000, "url is null!");
}
k kVar = new k(str);
kVar.bQs = true;
kVar.bQt = z;
kVar.bPY = str2;
kVar.bJa = i;
kVar.cFW = z2;
kVar.b(str, z, str2, i);
return kVar;
}
private void b(String str, boolean z, String str2, int i) throws qh {
try {
getHostAddress();
if (z) {
if (str2 == null) {
str2 = "10.0.0.172";
}
if (i < 0) {
i = 80;
}
this.bQh = (HttpURLConnection) new URL(str).openConnection(new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(str2, i)));
this.bQl = true;
} else {
this.bQh = (HttpURLConnection) new URL(str).openConnection();
this.bQl = false;
}
this.bQh.setReadTimeout(ke.YP);
this.bQh.setConnectTimeout(this.bQq);
} catch (IOException e) {
throw new qh(-1056, "IOException : " + e.getMessage());
} catch (IllegalArgumentException e2) {
throw new qh(-1057, "IllegalArgumentException : " + e2.getMessage());
} catch (SecurityException e3) {
throw new qh(-1058, "SecurityException: " + e3.getMessage());
} catch (UnsupportedOperationException e4) {
throw new qh(-1059, "UnsupportedOperationException: " + e4.getMessage());
}
}
public void setRequestProperty(String str, String str2) {
if (str != null && str2 != null && this.bQh != null) {
this.bQh.setRequestProperty(str, str2);
this.bQk.put(str, str2);
}
}
public void a(Hashtable<String, String> hashtable) {
if (this.bQh != null && hashtable != null) {
for (Map.Entry<String, String> entry : hashtable.entrySet()) {
setRequestProperty(entry.getKey(), entry.getValue());
}
}
}
public void b(Hashtable<String, String> hashtable) {
if (hashtable != null && hashtable.size() != 0 && this.bQh != null) {
for (Map.Entry<String, String> entry : hashtable.entrySet()) {
this.bQh.setRequestProperty(entry.getKey(), entry.getValue());
}
}
}
public void setRequestMethod(String str) {
this.bQg = str;
if ("GET".equalsIgnoreCase(str)) {
this.bQg = "GET";
} else if ("POST".equalsIgnoreCase(str)) {
this.bQg = "POST";
}
}
public String getRequestMethod() {
return this.bQg;
}
public void E(byte[] bArr) {
this.bQi = bArr;
}
public byte[] Hc() {
return this.bQi;
}
public int Hd() throws qh {
int i;
int i2;
if (RW()) {
throw new qh(-1000, "sendRequest() is forbidden couldNotConnect");
}
if (this.cFW && "com.tencent.qqpimsecure".equals(TMSDKContext.getApplicaionContext().getPackageName())) {
Hk();
}
try {
if (uc.KF() < 8) {
System.setProperty("http.keepAlive", "false");
}
this.bQh.setUseCaches(false);
this.bQh.setRequestProperty("Pragma", "no-cache");
this.bQh.setRequestProperty("Cache-Control", "no-cache");
this.bQh.setInstanceFollowRedirects(false);
i = this.bQg;
} catch (IllegalAccessError e) {
e = e;
i = 0;
} catch (IllegalStateException e2) {
e = e2;
i = 0;
} catch (ProtocolException e3) {
e = e3;
i = 0;
} catch (SocketException e4) {
e = e4;
i = 0;
} catch (SocketTimeoutException e5) {
e = e5;
i = 0;
} catch (UnknownHostException e6) {
e = e6;
i = 0;
} catch (ClientProtocolException e7) {
e = e7;
i = 0;
} catch (qh e8) {
e = e8;
i = 0;
} catch (Exception e9) {
e = e9;
i = 0;
}
try {
if ("GET".equalsIgnoreCase(i)) {
i2 = -3000;
this.bQh.setRequestMethod("GET");
} else {
i2 = -2000;
this.bQh.setRequestMethod("POST");
if (!this.bQk.containsKey("Accept")) {
this.bQh.setRequestProperty("Accept", "*/*");
this.bQh.setRequestProperty("Accept-Charset", "utf-8");
}
this.bQh.setDoOutput(true);
this.bQh.setDoInput(true);
if (this.bQi != null) {
if (!this.bQk.containsKey("Content-Type")) {
this.bQh.setRequestProperty("Content-Type", "application/octet-stream");
}
this.bQh.setRequestProperty("Content-length", SQLiteDatabase.KeyEmpty + this.bQi.length);
long currentTimeMillis = System.currentTimeMillis();
OutputStream outputStream = this.bQh.getOutputStream();
long currentTimeMillis2 = System.currentTimeMillis() - currentTimeMillis;
if (currentTimeMillis2 > 0 && currentTimeMillis2 < BuglyBroadcastRecevier.cuk && cMR.size() <= 4) {
synchronized (cMR) {
cMR.add(new Pair<>(Integer.valueOf(y.dwt), Long.valueOf(currentTimeMillis2)));
if (4 == cMR.size()) {
StringBuilder sb = new StringBuilder();
for (int i3 = 0; i3 < cMR.size(); i3++) {
Pair<Integer, Long> pair = cMR.get(i3);
if (pair != null) {
sb.append(pair.first);
sb.append(",");
sb.append(pair.second);
if (cMR.size() - 1 != i3) {
sb.append("|");
}
}
}
adr = sb.toString();
new t("wup").b("cn_t_a", adr, true);
}
}
}
outputStream.write(this.bQi);
outputStream.flush();
outputStream.close();
}
}
this.bQj = this.bQh.getResponseCode();
if (this.bQj >= 301 && this.bQj <= 305) {
byte b = this.bQn;
this.bQn = (byte) (b + 1);
if (b < 3) {
this.aOm = Hg();
return He();
}
} else if (this.bQj == 200) {
String contentType = getContentType();
if (this.bQl && contentType != null && contentType.toLowerCase().indexOf("vnd.wap.wml") != -1) {
byte b2 = this.bQo;
this.bQo = (byte) (b2 + 1);
if (b2 < 1) {
return He();
}
}
}
if (this.bQj != 206 && this.bQj != 200) {
byte b3 = this.bQp;
this.bQp = (byte) (b3 + 1);
if (b3 < 2) {
if (i2 == -1 && "true".equals(System.getProperty("http.keepAlive"))) {
System.setProperty("http.keepAlive", "false");
}
return He();
}
throw new qh(this.bQj + i2, "response code is unnormal: " + this.bQj + " SDK Version:" + uc.KF());
}
return this.bQj;
} catch (IllegalAccessError e10) {
e = e10;
byte b4 = this.bQp;
this.bQp = (byte) (b4 + 1);
if (b4 < 2) {
return He();
}
throw new qh(i - 60, "sendRequest IllegalAccessError: " + e.getMessage());
} catch (IllegalStateException e11) {
e = e11;
byte b5 = this.bQp;
this.bQp = (byte) (b5 + 1);
if (b5 < 2) {
return He();
}
throw new qh(i - 61, "sendRequest IllegalStateException: " + e.getMessage());
} catch (ProtocolException e12) {
e = e12;
byte b6 = this.bQp;
this.bQp = (byte) (b6 + 1);
if (b6 < 2) {
return He();
}
throw new qh(i - 51, "sendRequest ProtocolException: " + e.getMessage());
} catch (SocketException e13) {
e = e13;
byte b7 = this.bQp;
this.bQp = (byte) (b7 + 1);
if (b7 < 2) {
return He();
}
throw new qh(i - 54, "sendRequest SocketException: " + e.getMessage());
} catch (SocketTimeoutException e14) {
e = e14;
byte b8 = this.bQp;
this.bQp = (byte) (b8 + 1);
if (b8 < 2) {
this.bQq = 60000;
this.bQr = 60000;
return He();
}
throw new qh(i - 55, "sendRequest" + e.getMessage());
} catch (UnknownHostException e15) {
e = e15;
byte b9 = this.bQp;
this.bQp = (byte) (b9 + 1);
if (b9 < 2) {
getHostAddress();
return He();
}
if (this.bQm) {
this.bQm = false;
close();
if (this.bQl) {
a(this.aOm, ae.bC);
} else if (ae.by == tz.KA()) {
String KC = tz.KC();
if (KC != null && KC.length() > 0 && tz.Eg() > 0) {
a(this.aOm, ae.bA);
} else {
throw new qh(i - 62, "sendRequest UnknownHostException: " + e.getMessage() + " networktype:" + tz.KA());
}
}
if (this.bQh != null) {
setRequestMethod(this.bQg);
if ("POST".equalsIgnoreCase(this.bQg) && this.bQi != null) {
E(this.bQi);
}
b(this.bQk);
return Hd();
}
}
throw new qh(i - 62, "sendRequest UnknownHostException: " + e.getMessage() + " networktype:" + tz.KA());
} catch (ClientProtocolException e16) {
e = e16;
byte b10 = this.bQp;
this.bQp = (byte) (b10 + 1);
if (b10 < 2) {
return He();
}
throw new qh(i - 51, "sendRequest ClientProtocolException: " + e.getMessage());
} catch (qh e17) {
e = e17;
byte b11 = this.bQp;
this.bQp = (byte) (b11 + 1);
if (b11 < 2) {
return He();
}
throw new qh(i - 56, "sendRequest NetWorkException: " + e.getMessage());
} catch (Exception e18) {
e = e18;
byte b12 = this.bQp;
this.bQp = (byte) (b12 + 1);
if (b12 < 2) {
return He();
}
throw new qh(i, "sendRequest " + e.getClass().getName() + " : " + e.getMessage());
}
}
private int He() throws qh {
close();
if (!this.bQs) {
if (tz.KA().value() == 0) {
throw new qh(-1052, "no connecition!");
}
a(this.aOm, tz.KA());
} else {
b(this.aOm, this.bQt, this.bPY, this.bJa);
}
setRequestMethod(this.bQg);
if ("POST".equalsIgnoreCase(this.bQg) && this.bQi != null) {
E(this.bQi);
}
b(this.bQk);
return Hd();
}
public int a(boolean z, AtomicReference<byte[]> atomicReference) throws qh {
if (this.bQh == null || !isConnected()) {
return -4000;
}
try {
atomicReference.set(g(z ? new InflaterInputStream(this.bQh.getInputStream()) : this.bQh.getInputStream()));
return 0;
} catch (qh e) {
throw new qh(e.GT() - 4000, "get response exception : " + e.getMessage());
} catch (Exception e2) {
throw new qh(-4002, "get response exception : " + e2.getMessage());
}
}
private byte[] g(InputStream inputStream) throws qh {
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
byte[] bArr = new byte[2048];
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
while (true) {
try {
try {
int read = inputStream.read(bArr);
if (read == -1) {
break;
}
byteArrayOutputStream.write(bArr, 0, read);
} catch (IOException e) {
throw new qh(-56, "get Bytes from inputStream when read buffer: " + e.getMessage());
}
} catch (Throwable th) {
try {
bufferedInputStream.close();
} catch (Exception e2) {
e2.printStackTrace();
}
try {
byteArrayOutputStream.close();
throw th;
} catch (Exception e3) {
e3.printStackTrace();
throw th;
}
}
}
byte[] byteArray = byteArrayOutputStream.toByteArray();
try {
bufferedInputStream.close();
} catch (Exception e4) {
e4.printStackTrace();
}
try {
byteArrayOutputStream.close();
} catch (Exception e5) {
e5.printStackTrace();
}
return byteArray;
}
public InputStream getInputStream() throws qh {
try {
return this.bQh.getInputStream();
} catch (Exception e) {
throw new qh(-56, "get inputStream: " + e.getMessage());
}
}
private boolean isConnected() {
return this.bQj == 200 || this.bQj == 206;
}
public int getResponseCode() {
return this.bQj;
}
public void close() {
if (this.bQh != null) {
try {
this.bQh.disconnect();
} catch (Exception e) {
}
this.bQh = null;
}
}
public String getHeaderField(String str) throws qh {
try {
return this.bQh.getHeaderField(str);
} catch (Exception e) {
throw new qh(-56, "get header field: " + e.getMessage());
}
}
public long Hf() throws qh {
String headerField = getHeaderField("Content-Range");
if (headerField == null) {
return -1L;
}
try {
return Long.parseLong(headerField.substring(headerField.lastIndexOf(47) + 1).trim());
} catch (Exception e) {
throw new qh(-56, "get breakpoint total size: " + e.getMessage());
}
}
public long getContentLength() throws qh {
String headerField = getHeaderField("content-length");
if (headerField == null) {
return -1L;
}
try {
return Long.parseLong(headerField.trim());
} catch (Exception e) {
throw new qh(-56, "get content length: " + e.getMessage());
}
}
public String getContentType() throws qh {
try {
return this.bQh.getHeaderField("Content-Type");
} catch (Exception e) {
throw new qh(-56, "get content type: " + e.getMessage());
}
}
public String Hg() throws qh {
try {
return this.bQh.getHeaderField("Location");
} catch (Exception e) {
throw new qh(-56, "get redirect url: " + e.getMessage());
}
}
public boolean Hh() {
return this.bQl;
}
public String Hi() {
String str = null;
if (this.bQh != null) {
str = this.bQh.getURL().toString();
}
if (str != null && str.length() != 0) {
this.aOm = str;
}
return this.aOm;
}
private Hashtable<String, String> Hj() {
return this.bQk;
}
public class a implements uh.a {
private a() {
}
@Override
public void d(boolean z, boolean z2) {
if (k.bQv != null && k.bQv.equals(uh.getSSID()) && k.bQw) {
if (!z2) {
boolean unused = k.bQu = z;
} else {
boolean unused2 = k.bQu = true;
}
boolean unused3 = k.bQx = z2;
boolean unused4 = k.bQw = false;
}
}
}
private void Hk() throws qh {
if (ae.by == tz.KA()) {
long currentTimeMillis = System.currentTimeMillis();
while (bQw) {
if (System.currentTimeMillis() - currentTimeMillis > anr.dZK) {
if (System.currentTimeMillis() - currentTimeMillis < 10000) {
break;
} else {
currentTimeMillis = System.currentTimeMillis();
}
}
}
if (bQu && !bQw && !bQx) {
throw new qh(-1063, "wifi need approve!");
}
if (bQw) {
bQu = true;
}
}
}
private String[] split(String str) {
String[] strArr = new String[2];
int indexOf = str.indexOf("://");
if (-1 != indexOf) {
str = str.substring(indexOf + 3);
}
int indexOf2 = str.indexOf("/");
if (-1 != indexOf2) {
strArr[0] = str.substring(0, indexOf2);
strArr[1] = str.substring(indexOf2);
} else {
strArr[0] = str;
strArr[1] = SQLiteDatabase.KeyEmpty;
}
return strArr;
}
public String getHostAddress() {
if (this.aOm == null) {
return SQLiteDatabase.KeyEmpty;
}
String host = this.bQh != null ? this.bQh.getURL().getHost() : split(this.aOm)[0];
if ((host == null || host.length() == 0) && this.bQh == null) {
host = split(this.aOm)[0];
}
try {
InetAddress byName = InetAddress.getByName(host);
if (byName != null) {
return byName.getHostAddress();
}
} catch (SecurityException e) {
e.printStackTrace();
} catch (UnknownHostException e2) {
e2.printStackTrace();
}
return SQLiteDatabase.KeyEmpty;
}
}