同程有借 v1.0.0版本的 MD5 值为:e33397cdbab33543d0c134ec96d77fb8
以下内容为反编译后的 a.java 源代码,内容仅作参考
package com.bonree.sdk.bb;
import android.text.TextUtils;
import com.bonree.sdk.aj.c;
import com.bonree.sdk.b.a;
import com.bonree.sdk.bl.f;
import com.taobao.accs.common.Constants;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class a extends c {
private static final String f4061n = "BR-Ping-Thread";
private final String f4062f;
private final List<Long> f4063g;
private volatile String f4064h;
private volatile AtomicLong f4065i;
private final List<String> f4066j;
private String f4067k;
private int f4068l;
private final int f4069m;
private final Runnable f4070o;
public static class C0054a {
private static final a f4071a = new a((byte) 0);
}
a(byte b9) {
this();
}
private a() {
super(null);
this.f4062f = "tcpping";
this.f4063g = Collections.synchronizedList(new ArrayList(5));
this.f4065i = new AtomicLong(0L);
this.f4066j = Collections.synchronizedList(new ArrayList());
this.f4067k = "";
this.f4068l = 80;
this.f4069m = 15000;
this.f4070o = new b(this);
}
private boolean c(String str) {
int parseInt;
try {
URL url = new URL(str);
url.getHost();
if (url.getPort() == -1) {
str.startsWith("https://");
} else {
url.getPort();
}
return true;
} catch (Throwable th) {
this.f4023c.e("ad: %s ,tcpping host parse filed: %s", str, th);
try {
Matcher matcher = Pattern.compile("((\\d+\\.){3}\\d+)|((\\d+\\.){3}\\d+)\\:(\\d+)").matcher(str);
if (matcher.find()) {
matcher.group(1);
try {
parseInt = Integer.parseInt(matcher.group(2));
} catch (NumberFormatException unused) {
}
if (parseInt < 0 || parseInt > 65535) {
throw new NumberFormatException();
}
return true;
}
} catch (Throwable th2) {
this.f4023c.e("ad: %s ,tcpping ip parse filed: %s", str, th2);
}
return false;
}
}
public static a e() {
return C0054a.f4071a;
}
private void f() {
int port;
try {
URL url = new URL(this.f4064h);
this.f4067k = url.getHost();
if (url.getPort() == -1) {
port = this.f4064h.startsWith("https://") ? Constants.PORT : 80;
} else {
port = url.getPort();
}
this.f4068l = port;
if (port < 0 || port > 65535) {
this.f4068l = 80;
}
} catch (Throwable th) {
this.f4023c.e("ad: %s ,tcpping host parse filed: %s", this.f4064h, th);
try {
Matcher matcher = Pattern.compile("((\\d+\\.){3}\\d+)|((\\d+\\.){3}\\d+)\\:(\\d+)").matcher(this.f4064h);
if (matcher.find()) {
this.f4067k = matcher.group(1);
try {
int parseInt = Integer.parseInt(matcher.group(2));
this.f4068l = parseInt;
if (parseInt < 0 || parseInt > 65535) {
throw new NumberFormatException();
}
} catch (NumberFormatException unused) {
this.f4068l = 80;
}
}
} catch (Throwable th2) {
this.f4023c.e("ad: %s ,tcpping ip parse filed: %s", this.f4064h, th2);
}
}
}
private void g() {
if (TextUtils.isEmpty(this.f4067k)) {
this.f4067k = "www.baidu.com";
}
if (this.f4068l == 0) {
this.f4068l = 80;
}
}
public final long d() {
int size = this.f4063g.size();
if (size != 0) {
return this.f4065i.get() / size;
}
return 0L;
}
public final void a(long j9) {
if (this.f4063g.size() >= 5) {
this.f4063g.remove(0);
}
this.f4063g.add(Long.valueOf(j9));
this.f4065i.getAndSet(0L);
for (Long l9 : this.f4063g) {
this.f4065i.getAndSet(this.f4065i.get() + l9.longValue());
}
}
public final void b(String str) {
String[] split;
int port;
this.f4023c.c("tcpping setTcpPingAddress: %s ", str);
if (str != null && !TextUtils.isEmpty(str.trim())) {
for (String str2 : str.split("\\,")) {
if (c(str2)) {
this.f4066j.add(str2);
}
}
if (this.f4066j.size() > 0) {
this.f4064h = this.f4066j.get(0);
try {
URL url = new URL(this.f4064h);
this.f4067k = url.getHost();
if (url.getPort() == -1) {
port = this.f4064h.startsWith("https://") ? Constants.PORT : 80;
} else {
port = url.getPort();
}
this.f4068l = port;
if (port < 0 || port > 65535) {
this.f4068l = 80;
return;
}
return;
} catch (Throwable th) {
this.f4023c.e("ad: %s ,tcpping host parse filed: %s", this.f4064h, th);
try {
Matcher matcher = Pattern.compile("((\\d+\\.){3}\\d+)|((\\d+\\.){3}\\d+)\\:(\\d+)").matcher(this.f4064h);
if (matcher.find()) {
this.f4067k = matcher.group(1);
try {
int parseInt = Integer.parseInt(matcher.group(2));
this.f4068l = parseInt;
if (parseInt < 0 || parseInt > 65535) {
throw new NumberFormatException();
}
return;
} catch (NumberFormatException unused) {
this.f4068l = 80;
return;
}
}
return;
} catch (Throwable th2) {
this.f4023c.e("ad: %s ,tcpping ip parse filed: %s", this.f4064h, th2);
return;
}
}
}
return;
}
this.f4067k = "";
}
@Override
public final synchronized boolean a() {
try {
if (!TextUtils.isEmpty(this.f4067k)) {
if (!this.f4021a) {
a("tcpping", a.EnumC0053a.f4026a);
this.f4021a = true;
a(f4061n);
a(this.f4070o, 0L);
a("tcpping", a.EnumC0053a.f4028c);
}
} else {
this.f4023c.c("tcpping tcpHost is null, service start failed!", new Object[0]);
b();
}
} catch (Throwable th) {
f fVar = this.f4023c;
if (fVar != null) {
fVar.a("tcp ping service start error. %s ", th);
}
b();
}
return true;
}
@Override
public final synchronized boolean b() {
try {
if (this.f4021a) {
a("tcpping", a.EnumC0053a.f4029d);
this.f4021a = false;
a_();
List<Long> list = this.f4063g;
if (list != null && list.size() > 0) {
this.f4063g.clear();
}
if (this.f4065i != null) {
this.f4065i.getAndSet(0L);
}
a("tcpping", a.EnumC0053a.f4030e);
} else {
this.f4023c.d("TcpPingService no need stop!", new Object[0]);
}
} catch (Throwable th) {
f fVar = this.f4023c;
if (fVar != null) {
fVar.a("tcp ping service stop error. ", th);
}
}
return true;
}
}