工作空间 v3.6.5.2版本的 MD5 值为:58e65af156c65a63bf64ed2e64960853
以下内容为反编译后的 UUSdpClient.java 源代码,内容仅作参考
package com.uusafe.sdp.bridge;
import android.app.Activity;
import android.app.Application;
import android.content.ContentResolver;
import android.content.Context;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.uusafe.base.modulesdk.module.bean.PushCode;
import com.uusafe.sandbox.netsvr.VpnServiceBaseImpl;
import com.uusafe.sdp.R;
import com.uusafe.sdp.bridge.bean.info.AppPolicyDetail;
import com.uusafe.sdp.bridge.bean.info.UUSdpAccessInfo;
import com.uusafe.sdp.bridge.bean.info.UUSdpGatewayInfo;
import com.uusafe.sdp.bridge.bean.info.UUSdpInitInfo;
import com.uusafe.sdp.bridge.bean.info.UUSdpUpdateInfo;
import com.uusafe.sdp.bridge.bean.info.UUSdpUserInfo;
import com.uusafe.sdp.bridge.bean.req.UUSdpLoginRequestInfo;
import com.uusafe.sdp.bridge.bean.req.UUSdpModifyPasswordRequestInfo;
import com.uusafe.sdp.bridge.bean.req.UUSdpRefreshSmsRequestInfo;
import com.uusafe.sdp.bridge.bean.rsp.UUSdpLoginResponseInfo;
import com.uusafe.sdp.bridge.listener.SdpScreenReceiver;
import com.uusafe.sdp.bridge.listener.UUSdpEmmCallback;
import com.uusafe.sdp.bridge.listener.UUSdpGatewayInfoChangeListener;
import com.uusafe.sdp.bridge.listener.UUSdpLoginCallback;
import com.uusafe.sdp.bridge.listener.UUSdpLogoutCallback;
import com.uusafe.sdp.bridge.listener.UUSdpModifyPasswordCallback;
import com.uusafe.sdp.bridge.listener.UUSdpRefreshSmsCallback;
import com.uusafe.sdp.bridge.listener.UUSdpTunnelStateListener;
import com.uusafe.sdp.channel.android.backend.GoBackend;
import com.uusafe.sdp.invoke.util.PreferenceUtils;
import com.uusafe.sdp.proguard.C0484a;
import com.uusafe.sdp.proguard.C0485b;
import com.uusafe.sdp.proguard.C0486c;
import com.uusafe.sdp.proguard.C0488e;
import com.uusafe.sdp.proguard.C0492i;
import com.uusafe.sdp.proguard.C0493j;
import com.uusafe.sdp.proguard.C0494k;
import com.uusafe.sdp.proguard.C0497n;
import com.uusafe.sdp.proguard.a0;
import com.uusafe.sdp.proguard.b0;
import com.uusafe.sdp.proguard.d1;
import com.uusafe.sdp.proguard.f0;
import com.uusafe.sdp.proguard.g0;
import com.uusafe.sdp.proguard.g1;
import com.uusafe.sdp.proguard.h0;
import com.uusafe.sdp.proguard.i0;
import com.uusafe.sdp.proguard.j1;
import com.uusafe.sdp.proguard.l0;
import com.uusafe.sdp.proguard.m0;
import com.uusafe.sdp.proguard.n0;
import com.uusafe.sdp.proguard.o1;
import com.uusafe.sdp.proguard.q0;
import com.uusafe.sdp.proguard.r;
import com.uusafe.sdp.proguard.r0;
import com.uusafe.sdp.proguard.s;
import com.uusafe.sdp.proguard.s0;
import com.uusafe.sdp.proguard.t0;
import com.uusafe.sdp.proguard.u0;
import com.uusafe.sdp.proguard.u1;
import com.uusafe.sdp.proguard.v0;
import com.uusafe.sdp.proguard.w0;
import com.uusafe.sdp.proguard.x0;
import com.uusafe.sdp.proguard.y0;
import com.uusafe.sdp.proguard.z0;
import com.xiaomi.mipush.sdk.Constants;
import java.io.ByteArrayInputStream;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
public class UUSdpClient implements r0.a, s0.a {
private static final String DIR_APP = "uusafe";
private static final String DIR_LOG = "safelink";
public static final int HEART_KILL_10001 = 10001;
public static final int HEART_KILL_10002 = 10002;
public static final int HEART_KILL_10003 = 10003;
public static final int HEART_KILL_10004 = 10004;
public static final int HEART_KILL_10005 = 10005;
public static final int HEART_KILL_10006 = 10006;
public static final int HEART_KILL_10007 = 10007;
public static final String SDP_NAME = "SafeLink";
public static final String SDP_VERSION = "1.2.5";
private static final String SERVER_PROVIDER_AUTHORITIES = ".SdpBridgeProvider";
private static final String SERVER_PROVIDER_SCHEME = "content://";
public static boolean SM_ENCRYPT = false;
public static final String TAG = "SafeLink";
private static final String TUNNEL_DEAFULT_NAME = "SafeLink";
private static UUSdpClient instance;
private GoBackend backend;
private long checkTime;
private Context context;
private Activity currentActivity;
private List<InetAddress> currentDnsServers;
private Properties heartReqProperties;
private r heartRsp;
private int lastErrorCode;
private long lastHeartTime;
private C0497n loginReq;
private s loginRsp;
private r0 uuNetWorkStateReceiver;
private UUSdpEmmCallback uuSdpEmmCallback;
private ArrayList<UUSdpGatewayInfo> uuSdpGatewayInfos;
private UUSdpLoginCallback uuSdpLoginCallback;
private s0 uuSdpTunnel;
private VpnServiceBaseImpl vpnServiceBase;
private n0 heartAlarm = null;
private int ht = 60;
private ArrayList<UUSdpTunnelStateListener> uuSdpTunnelStateListeners = new ArrayList<>();
private ArrayList<UUSdpGatewayInfoChangeListener> uuSdpGatewayInfoChangeListeners = new ArrayList<>();
private int tunnelCloseCode = 110;
private boolean isZlogInit = true;
private String cid = null;
private boolean startThirdApp = false;
private boolean multipleSdk = true;
private boolean v1 = false;
private boolean autoLogin = false;
private boolean kickedByServer = false;
private ArrayList<AppPolicyDetail> appPolicyDetails = new ArrayList<>();
public final int interval = 1000;
private boolean reConnect = false;
public class a implements Application.ActivityLifecycleCallbacks {
public int f6335a = 0;
public a() {
}
@Override
public void onActivityCreated(Activity activity, Bundle bundle) {
}
@Override
public void onActivityDestroyed(Activity activity) {
}
@Override
public void onActivityPaused(Activity activity) {
}
@Override
public void onActivityResumed(Activity activity) {
if (activity != null) {
UUSdpClient.this.currentActivity = activity;
}
}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
}
@Override
public void onActivityStarted(Activity activity) {
int i = this.f6335a + 1;
this.f6335a = i;
if (i == 1) {
q0.c("SafeLink", "activityStartCount===1, AppInForeground", new Object[0]);
UUSdpClient.getInstance(UUSdpClient.this.context).checkHeart();
}
}
@Override
public void onActivityStopped(Activity activity) {
int i = this.f6335a - 1;
this.f6335a = i;
if (i == 0) {
q0.c("SafeLink", "activityStartCount===0, AppInBackground", new Object[0]);
}
}
}
public class c implements h0 {
public final UUSdpModifyPasswordCallback f6340a;
public c(UUSdpClient uUSdpClient, UUSdpModifyPasswordCallback uUSdpModifyPasswordCallback) {
this.f6340a = uUSdpModifyPasswordCallback;
}
@Override
public void onError(int i) {
this.f6340a.onError(i);
}
@Override
public void onSuccess() {
this.f6340a.onSuccess();
}
}
public class d implements i0 {
public final UUSdpRefreshSmsCallback f6341a;
public d(UUSdpClient uUSdpClient, UUSdpRefreshSmsCallback uUSdpRefreshSmsCallback) {
this.f6341a = uUSdpRefreshSmsCallback;
}
@Override
public void onError(int i) {
this.f6341a.onError(i);
}
@Override
public void onSuccess() {
this.f6341a.onSuccess();
}
}
public class f implements UUSdpLoginCallback {
public f() {
}
@Override
public void onError(int i, UUSdpLoginResponseInfo uUSdpLoginResponseInfo) {
q0.a("SafeLink", "Sdp reConnect error,errorCode:" + i, new Object[0]);
}
@Override
public void onSuccess(UUSdpLoginResponseInfo uUSdpLoginResponseInfo) {
q0.a("SafeLink", "Sdp reConnect success,tunnel open", new Object[0]);
UUSdpClient.this.setKickedByServer(false);
}
}
public class g implements Runnable {
public g() {
}
@Override
public void run() {
UUSdpClient.this.heartBeat();
}
}
public class h implements Runnable {
public h() {
}
@Override
public void run() {
UUSdpClient.this.heartBeat();
}
}
private UUSdpClient(Context context) {
if (context != null) {
this.context = context.getApplicationContext();
this.vpnServiceBase = new VpnServiceBaseImpl();
return;
}
throw new IllegalArgumentException("Context must not be empty.");
}
private boolean checkSdpLogin() {
if (this.multipleSdk) {
ContentResolver contentResolver = this.context.getContentResolver();
Bundle bundle = new Bundle();
String lastPackageName = PreferenceUtils.getLastPackageName(this.context);
if (lastPackageName != null && !lastPackageName.equals(this.context.getPackageName())) {
try {
if (contentResolver.call(Uri.parse("content://" + lastPackageName + SERVER_PROVIDER_AUTHORITIES), "getTunnelState", (String) null, bundle).getInt("state") == 1) {
q0.c("SafeLink", "UUSdpClient multipleSdk has login", new Object[0]);
return true;
}
} catch (Exception e2) {
q0.c("SafeLink", "UUSdpClient multipleSdk Exception =" + e2.getMessage(), new Object[0]);
}
}
return false;
}
return false;
}
private boolean checkSecurity(C0492i c0492i) throws Exception {
String[] split;
String allowNetworkAccess = c0492i.getAllowNetworkAccess();
int c2 = l0.c(this.context);
if ((allowNetworkAccess.equals("10") && c2 == 0) || (allowNetworkAccess.equals(HiAnalyticsConstant.KeyAndValue.NUMBER_01) && c2 == 1)) {
try {
this.tunnelCloseCode = 1001;
this.backend.b(this.uuSdpTunnel, u0.a.DOWN, null);
q0.c("SafeLink", "SecurityConfig allowNetworkAccess cause Tunnel closed", new Object[0]);
return true;
} catch (Exception e2) {
q0.a("SafeLink", e2);
}
}
String wifiWhiteList = c0492i.getWifiWhiteList();
if (wifiWhiteList != null && (split = wifiWhiteList.split(Constants.ACCEPT_TIME_SEPARATOR_SP)) != null && split.length > 0 && ((allowNetworkAccess.equals("10") || allowNetworkAccess.equals(PushCode.DEVICE_ERASE)) && c2 == 1)) {
String f2 = l0.f(this.context);
boolean z = false;
for (String str : split) {
if (str.equalsIgnoreCase(f2)) {
z = true;
}
}
if (!z) {
try {
this.tunnelCloseCode = 1001;
this.backend.b(this.uuSdpTunnel, u0.a.DOWN, null);
q0.c("SafeLink", "SecurityConfig wifi wifiWhiteList cause Tunnel closed", new Object[0]);
return true;
} catch (Exception e3) {
q0.a("SafeLink", e3);
}
}
}
int safeWifiAccess = c0492i.getSafeWifiAccess();
int e4 = l0.e(this.context);
if (safeWifiAccess == 1 && e4 == 0) {
try {
this.tunnelCloseCode = 1001;
this.backend.b(this.uuSdpTunnel, u0.a.DOWN, null);
q0.c("SafeLink", "SecurityConfig wifi safeWifiAccess cause Tunnel closed", new Object[0]);
return true;
} catch (Exception e5) {
q0.a("SafeLink", e5);
}
}
return false;
}
private void closeTunnel(final UUSdpLogoutCallback uUSdpLogoutCallback) {
if (this.uuSdpTunnel != null) {
new Thread(new Runnable() {
@Override
public final void run() {
UUSdpClient.this.a(uUSdpLogoutCallback);
}
}).start();
} else if (uUSdpLogoutCallback != null) {
uUSdpLogoutCallback.onError(101);
q0.b("SafeLink", "closeTunnel error SDP_TUNNEL_NULL:101", new Object[0]);
}
}
private void generateHeartProperties(r rVar) {
if (rVar == null) {
if (this.loginReq.getCid() != null) {
this.heartReqProperties.setProperty(C0484a.z, this.loginReq.getCid());
this.cid = this.loginReq.getCid();
}
if (this.loginRsp.getData().getCft() != null) {
this.heartReqProperties.setProperty(C0484a.A, this.loginRsp.getData().getCft());
}
if (this.loginRsp.getData().getSct() != null) {
this.heartReqProperties.setProperty(C0484a.B, this.loginRsp.getData().getSct());
}
if (this.loginRsp.getData().getDt() != null) {
this.heartReqProperties.setProperty(C0484a.C, this.loginRsp.getData().getDt());
}
if (this.loginRsp.getData().getHt() != 0) {
Properties properties = this.heartReqProperties;
String str = C0484a.D;
properties.setProperty(str, "" + this.loginRsp.getData().getHt());
}
if (this.loginRsp.getData().getApt() != null) {
this.heartReqProperties.setProperty(C0484a.E, this.loginRsp.getData().getApt());
return;
}
return;
}
if (rVar.getData().getCft() != null) {
this.heartReqProperties.setProperty(C0484a.A, rVar.getData().getCft());
}
if (rVar.getData().getSct() != null) {
this.heartReqProperties.setProperty(C0484a.B, rVar.getData().getSct());
}
if (rVar.getData().getDt() != null) {
this.heartReqProperties.setProperty(C0484a.C, rVar.getData().getDt());
}
if (rVar.getData().getHt() != 0) {
Properties properties2 = this.heartReqProperties;
String str2 = C0484a.D;
properties2.setProperty(str2, "" + rVar.getData().getHt());
}
if (this.loginRsp.getData().getApt() != null) {
this.heartReqProperties.setProperty(C0484a.E, this.loginRsp.getData().getApt());
}
}
public UUSdpLoginResponseInfo generateLoginResponseInfo(s sVar) {
UUSdpLoginResponseInfo uUSdpLoginResponseInfo = new UUSdpLoginResponseInfo();
if (sVar != null) {
uUSdpLoginResponseInfo.setExtendParam(sVar.getExtendParam());
}
if (sVar.getData() == null) {
return uUSdpLoginResponseInfo;
}
if (sVar.getData().getUinfo() != null) {
UUSdpUserInfo uUSdpUserInfo = new UUSdpUserInfo();
uUSdpUserInfo.setEmail(sVar.getData().getUinfo().getEmail());
uUSdpUserInfo.setLoginName(sVar.getData().getUinfo().getLoginName());
uUSdpUserInfo.setCountryCode(sVar.getData().getUinfo().getCountryCode());
uUSdpUserInfo.setPhoneNum(sVar.getData().getUinfo().getPhoneNum());
uUSdpUserInfo.setUserId(sVar.getData().getUinfo().getUserId());
uUSdpUserInfo.setUserName(sVar.getData().getUinfo().getUserName());
uUSdpLoginResponseInfo.setUserInfo(uUSdpUserInfo);
}
if (sVar.getData().getAis() != null && sVar.getData().getAis().length > 0) {
ArrayList<UUSdpAccessInfo> arrayList = new ArrayList<>();
for (int i = 0; i < sVar.getData().getAis().length; i++) {
C0485b c0485b = sVar.getData().getAis()[i];
UUSdpAccessInfo uUSdpAccessInfo = new UUSdpAccessInfo();
uUSdpAccessInfo.setIconId(c0485b.getIconId());
uUSdpAccessInfo.setName(c0485b.getName());
uUSdpAccessInfo.setType(c0485b.getType());
uUSdpAccessInfo.setUrl(c0485b.getUrl());
arrayList.add(uUSdpAccessInfo);
}
uUSdpLoginResponseInfo.setAccessInfo(arrayList);
}
if (sVar.getData().getUi() != null) {
C0494k ui = sVar.getData().getUi();
UUSdpUpdateInfo uUSdpUpdateInfo = new UUSdpUpdateInfo();
uUSdpUpdateInfo.setDescription(ui.getDescription());
uUSdpUpdateInfo.setDownloadUrl(ui.getDownloadUrl());
uUSdpUpdateInfo.setUpdateFlag(ui.getUpdateFlag());
uUSdpUpdateInfo.setVersionName(ui.getVersionName());
uUSdpLoginResponseInfo.setUpdateInfo(uUSdpUpdateInfo);
}
if (sVar.getData().getGis() != null) {
ArrayList<UUSdpGatewayInfo> arrayList2 = new ArrayList<>();
for (int i2 = 0; i2 < sVar.getData().getGis().length; i2++) {
C0488e c0488e = sVar.getData().getGis()[i2];
UUSdpGatewayInfo uUSdpGatewayInfo = new UUSdpGatewayInfo();
uUSdpGatewayInfo.setIp(c0488e.getIp());
uUSdpGatewayInfo.setName(c0488e.getName());
arrayList2.add(uUSdpGatewayInfo);
}
uUSdpLoginResponseInfo.setGis(arrayList2);
this.uuSdpGatewayInfos = arrayList2;
}
uUSdpLoginResponseInfo.setVct(sVar.getData().getVct());
uUSdpLoginResponseInfo.setMpc(sVar.getData().getMpc());
uUSdpLoginResponseInfo.setMpf(sVar.getData().getMpf());
uUSdpLoginResponseInfo.setTicket(sVar.getData().getTicket());
uUSdpLoginResponseInfo.setV(sVar.getData().getV());
return uUSdpLoginResponseInfo;
}
private String getDnsSettings(s sVar) {
try {
y0 y0Var = new y0();
x0 x0Var = new x0();
for (InetAddress inetAddress : l0.b(this.context)) {
if (inetAddress.getHostAddress().indexOf(".") > 0) {
if (x0Var.getIpv4Preferred() == null) {
x0Var.setIpv4Preferred(inetAddress.getHostAddress());
} else if (x0Var.getIpv4Alternate() == null) {
x0Var.setIpv4Alternate(inetAddress.getHostAddress());
}
}
}
y0Var.setServer(x0Var);
w0 w0Var = new w0();
if (x0Var.getIpv4Preferred() != null) {
w0Var.setIpv4Preferred("198.51.100.1");
}
if (x0Var.getIpv4Alternate() != null) {
w0Var.setIpv4Alternate("10.255.255.255");
}
y0Var.setRoute(w0Var);
C0486c[] dns = sVar.getData().getDns();
int length = dns.length;
v0[] v0VarArr = new v0[length];
for (int i = 0; i < length; i++) {
C0486c c0486c = dns[i];
v0 v0Var = new v0();
v0Var.setName(c0486c.getName());
v0Var.setIpv4(c0486c.getIpv4());
v0Var.setIpv6(c0486c.getIpv6());
v0Var.setType(c0486c.getType());
v0VarArr[i] = v0Var;
}
y0Var.setHosts(v0VarArr);
return new u1().a(y0Var);
} catch (Exception unused) {
return "";
}
}
public static UUSdpClient getInstance(Context context) {
if (instance == null) {
instance = new UUSdpClient(context);
}
return instance;
}
public void heartBeat() {
StringBuffer stringBuffer;
Properties properties;
if (this.uuSdpTunnel == null) {
q0.b("SafeLink", "heartBeat error SDP_TUNNEL_NULL", new Object[0]);
return;
}
try {
stringBuffer = new StringBuffer();
Properties properties2 = this.heartReqProperties;
if (properties2 != null) {
for (Map.Entry entry : properties2.entrySet()) {
stringBuffer.append(entry.getKey());
stringBuffer.append("==");
stringBuffer.append(entry.getValue());
stringBuffer.append(";");
}
if (this.heartReqProperties.getProperty(C0484a.z) == null) {
this.heartReqProperties.setProperty(C0484a.z, this.cid);
}
}
properties = this.heartReqProperties;
} catch (Exception e2) {
e2.printStackTrace();
q0.b("SafeLink", "heartBeat error SDP_TUNNEL_ERROR:" + e2.getCause(), new Object[0]);
}
if (properties != null && properties.getProperty(C0484a.z) != null) {
q0.a("SafeLink", "heartBeat start==" + stringBuffer.toString() + "=cid=" + this.cid, new Object[0]);
C0484a.a(this.context).a(this.heartReqProperties);
startAlarm();
return;
}
q0.b("SafeLink", "heartBeat error ,no cid!!! logout", new Object[0]);
logoutInternal(null);
}
public void loginError(int i, UUSdpLoginResponseInfo uUSdpLoginResponseInfo) {
if (this.uuSdpLoginCallback != null) {
if (uUSdpLoginResponseInfo == null) {
uUSdpLoginResponseInfo = new UUSdpLoginResponseInfo();
}
UUSdpLoginCallback uUSdpLoginCallback = this.uuSdpLoginCallback;
this.uuSdpLoginCallback = null;
uUSdpLoginCallback.onError(i, uUSdpLoginResponseInfo);
return;
}
q0.c("SafeLink", "loginError but uuSdpLoginCallback==null", new Object[0]);
}
private void loginInternal(UUSdpLoginRequestInfo uUSdpLoginRequestInfo) {
SdpScreenReceiver.registerScreenReceiver(this.context);
new Thread(new Runnable() {
@Override
public final void run() {
UUSdpClient.this.a();
}
}).start();
try {
C0484a.a(this.context).a(uUSdpLoginRequestInfo, new b(uUSdpLoginRequestInfo.getSdpName() != null ? uUSdpLoginRequestInfo.getSdpName() : "SafeLink", uUSdpLoginRequestInfo));
} catch (Exception e2) {
q0.a("SafeLink", e2);
loginError(110, null);
}
}
private void loginSuccess(UUSdpLoginResponseInfo uUSdpLoginResponseInfo) {
if (this.uuSdpLoginCallback != null) {
if (this.multipleSdk) {
PreferenceUtils.setLastPackageName(this.context);
}
this.uuSdpLoginCallback.onSuccess(uUSdpLoginResponseInfo);
this.uuSdpLoginCallback = null;
return;
}
q0.c("SafeLink", "loginSuccess but uuSdpLoginCallback==null", new Object[0]);
}
private void logoutInternal(UUSdpLogoutCallback uUSdpLogoutCallback) {
q0.c("SafeLink", "UUSdpClient logoutInternal called", new Object[0]);
closeTunnel(uUSdpLogoutCallback);
SdpScreenReceiver.unRegisterScreenReceiver(this.context);
}
private void openTunnel(final String str, final int i, final ArrayList<String> arrayList, final s sVar, UUSdpLoginCallback uUSdpLoginCallback) {
this.appPolicyDetails.clear();
if (sVar != null) {
final String cf = sVar.getData().getCf();
if (cf == null) {
q0.b("SafeLink", "openTunnel-> login tunnelConfig is null", new Object[0]);
loginError(105, null);
return;
}
q0.d("SafeLink", "openTunnel-> start", new Object[0]);
q0.d("SafeLink", "openTunnel->tunnelConfig【" + cf + "】", new Object[0]);
new Thread(new Runnable() {
@Override
public final void run() {
UUSdpClient.this.a(cf, sVar, arrayList, str, i);
}
}).start();
return;
}
q0.b("SafeLink", "openTunnel->UUSdpClient login authResponse is null", new Object[0]);
loginError(105, null);
}
private boolean paramsCheck(UUSdpLoginRequestInfo uUSdpLoginRequestInfo) {
if (uUSdpLoginRequestInfo.getPassword() == null || uUSdpLoginRequestInfo.getCid() == null || uUSdpLoginRequestInfo.getCid().length() != 32) {
q0.c("SafeLink", "cid=" + uUSdpLoginRequestInfo.getCid(), new Object[0]);
return false;
}
return true;
}
private void processGatewayInfo(C0488e[] c0488eArr) {
if (c0488eArr == null) {
return;
}
if (c0488eArr.length != this.uuSdpGatewayInfos.size()) {
updateGatewayInfo(c0488eArr);
return;
}
boolean z = false;
for (C0488e c0488e : c0488eArr) {
for (int i = 0; i < this.uuSdpGatewayInfos.size(); i++) {
UUSdpGatewayInfo uUSdpGatewayInfo = this.uuSdpGatewayInfos.get(i);
if (!uUSdpGatewayInfo.getIp().equals(c0488e.getIp()) || !uUSdpGatewayInfo.getName().equals(c0488e.getName())) {
z = true;
break;
}
}
if (z) {
break;
}
}
if (z) {
updateGatewayInfo(c0488eArr);
}
}
public void processHeartRsp(r rVar) {
String dt;
String sct;
int ht;
String cft;
boolean z;
int aaf;
String apt;
C0492i sc;
if (rVar != null) {
try {
this.lastHeartTime = System.currentTimeMillis();
generateHeartProperties(rVar);
r rVar2 = this.heartRsp;
if (rVar2 == null) {
dt = this.loginRsp.getData().getDt();
} else {
dt = rVar2.getData().getDt();
}
if (rVar.getData().getDt() != null) {
rVar.getData().getDt().equals(dt);
}
r rVar3 = this.heartRsp;
if (rVar3 == null) {
sct = this.loginRsp.getData().getSct();
} else {
sct = rVar3.getData().getSct();
}
if (rVar.getData().getSct() == null || rVar.getData().getSct().equals(sct) || (sc = rVar.getData().getSc()) == null || !checkSecurity(sc)) {
r rVar4 = this.heartRsp;
if (rVar4 == null) {
ht = this.loginRsp.getData().getHt();
} else {
ht = rVar4.getData().getHt();
}
if (rVar.getData().getHt() != 0 && rVar.getData().getHt() != ht) {
this.heartAlarm.a(this.context);
this.ht = rVar.getData().getHt();
startAlarm();
}
r rVar5 = this.heartRsp;
if (rVar5 != null) {
processGatewayInfo(rVar5.getData().getGis());
}
r rVar6 = this.heartRsp;
if (rVar6 == null) {
cft = this.loginRsp.getData().getCft();
} else {
cft = rVar6.getData().getCft();
}
if (rVar.getData().getCft() == null || rVar.getData().getCft().equals(cft)) {
z = false;
} else {
String cf = rVar.getData().getCf();
q0.a("SafeLink", "Heart tunnelConfig【" + cf + "】", new Object[0]);
if (this.uuSdpTunnel != null) {
this.uuSdpTunnel.a(d1.a(new ByteArrayInputStream(cf.getBytes("UTF-8"))));
}
z = true;
}
r rVar7 = this.heartRsp;
if (rVar7 == null) {
aaf = this.loginRsp.getData().getAaf();
} else {
aaf = rVar7.getData().getAaf();
}
r rVar8 = this.heartRsp;
if (rVar8 == null) {
apt = this.loginRsp.getData().getApt();
} else {
apt = rVar8.getData().getApt();
}
if (rVar.getData().getAaf() != aaf || (rVar.getData().getApt() != null && apt != null && !rVar.getData().getApt().equals(apt))) {
q0.c("SafeLink", "processHeartRsp AllowedApplications changed oldAaf==" + aaf + "==" + rVar.getData().getAaf() + "==oldApt==" + apt + "==" + rVar.getData().getApt(), new Object[0]);
s0 s0Var = this.uuSdpTunnel;
if (s0Var != null) {
s0Var.a().clear();
if (rVar.getData().getAaf() == 1) {
Object apds = rVar.getData().getApds();
if (apds != null && (apds instanceof List)) {
for (Map map : (List) apds) {
if (map.get("pkn") != null) {
this.uuSdpTunnel.a().add(map.get("pkn").toString());
}
}
}
if (rVar.getData().getApt() != null && rVar.getData().getApt().length() > 0) {
this.uuSdpTunnel.a(new u1().a(apds));
}
} else {
this.uuSdpTunnel.a("");
}
}
z = true;
}
if (this.uuSdpTunnel.d() != rVar.getData().getDf() || (this.uuSdpTunnel.h() != null && rVar.getData().getDt() != null && !this.uuSdpTunnel.h().equals(rVar.getData().getDt()))) {
q0.c("SafeLink", "processHeartRsp df value changed uuSdpTunnel.getDf()==" + this.uuSdpTunnel.d() + "==" + rVar.getData().getDf(), new Object[0]);
this.uuSdpTunnel.b(getDnsSettings(rVar));
this.uuSdpTunnel.a(rVar.getData().getDf());
this.uuSdpTunnel.c(rVar.getData().getDt());
z = true;
}
if (z) {
q0.d("SafeLink", "processHeartRsp need reStart", new Object[0]);
reStartInternal();
}
this.heartRsp = rVar;
}
} catch (Exception e2) {
q0.b("SafeLink", "processHeartRsp Exception " + e2.getMessage(), new Object[0]);
q0.a("SafeLink", e2);
}
}
}
public void processLoginRsp(String str, int i, ArrayList<String> arrayList, C0497n c0497n, s sVar, UUSdpLoginCallback uUSdpLoginCallback) {
C0492i sc;
String[] split;
if (sVar != null) {
if (sVar.getData().getSc() != null && (sc = sVar.getData().getSc()) != null) {
String allowNetworkAccess = sc.getAllowNetworkAccess();
int c2 = l0.c(this.context);
if ((allowNetworkAccess.equals("10") && c2 == 0) || (allowNetworkAccess.equals(HiAnalyticsConstant.KeyAndValue.NUMBER_01) && c2 == 1)) {
q0.c("SafeLink", "LoginRsp SecurityConfig wifi wifiWhiteList cause Tunnel closed", new Object[0]);
loginError(102, null);
return;
}
String wifiWhiteList = sc.getWifiWhiteList();
if (wifiWhiteList != null && (split = wifiWhiteList.split(Constants.ACCEPT_TIME_SEPARATOR_SP)) != null && split.length > 0 && ((allowNetworkAccess.equals("10") || allowNetworkAccess.equals(PushCode.DEVICE_ERASE)) && c2 == 1)) {
String f2 = l0.f(this.context);
boolean z = false;
for (String str2 : split) {
if (str2.equalsIgnoreCase(f2)) {
z = true;
}
}
if (!z) {
q0.c("SafeLink", "LoginRsp SecurityConfig wifi wifiWhiteList cause Tunnel closed", new Object[0]);
loginError(102, null);
return;
}
}
int safeWifiAccess = sc.getSafeWifiAccess();
int e2 = l0.e(this.context);
if (safeWifiAccess == 1 && e2 == 0) {
q0.c("SafeLink", "LoginRsp SecurityConfig wifi safeWifiAccess cause Tunnel closed", new Object[0]);
loginError(102, null);
return;
}
}
sVar.getData().getDns();
if (sVar.getData().getHt() != 0) {
this.ht = sVar.getData().getHt();
}
this.loginReq = c0497n;
this.loginRsp = sVar;
openTunnel(str, i, arrayList, sVar, uUSdpLoginCallback);
}
}
private boolean reStartInternal() {
try {
if (this.uuSdpTunnel != null) {
q0.c("SafeLink", "Tunnel reStartInternal begin", new Object[0]);
GoBackend goBackend = this.backend;
s0 s0Var = this.uuSdpTunnel;
u0.a aVar = u0.a.UP;
if (goBackend.a(s0Var, aVar, s0Var.g()) == aVar) {
q0.c("SafeLink", "Tunnel reStartInternal success", new Object[0]);
return true;
}
q0.b("SafeLink", "Tunnel reStartInternal fail", new Object[0]);
} else {
q0.c("SafeLink", "Tunnel reStartInternal uuSdpTunnel==null", new Object[0]);
}
} catch (Exception e2) {
q0.a("SafeLink", e2);
}
return false;
}
private void setHeartBeatListener() {
C0484a.a(this.context).a(new e());
}
private void startAlarm() {
n0 n0Var = new n0(new h(), this.context.getMainLooper(), this.context);
this.heartAlarm = n0Var;
n0Var.a(this.ht * 1000, this.context);
}
private void updateGatewayInfo(C0488e[] c0488eArr) {
this.uuSdpGatewayInfos.clear();
for (C0488e c0488e : c0488eArr) {
UUSdpGatewayInfo uUSdpGatewayInfo = new UUSdpGatewayInfo();
uUSdpGatewayInfo.setIp(c0488e.getIp());
uUSdpGatewayInfo.setName(c0488e.getName());
this.uuSdpGatewayInfos.add(uUSdpGatewayInfo);
}
q0.a("SafeLink", "uuSdpGatewayInfoChangeListeners size:" + this.uuSdpGatewayInfoChangeListeners.size(), new Object[0]);
q0.a("SafeLink", "UUSdpGatewayInfoChangeListener onGatewayInfoChange", new Object[0]);
Iterator<UUSdpGatewayInfoChangeListener> it = this.uuSdpGatewayInfoChangeListeners.iterator();
while (it.hasNext()) {
it.next().onGatewayInfoChange(this.uuSdpGatewayInfos);
}
}
public void a(UUSdpLogoutCallback uUSdpLogoutCallback) {
try {
GoBackend goBackend = this.backend;
s0 s0Var = this.uuSdpTunnel;
u0.a aVar = u0.a.DOWN;
if (goBackend.b(s0Var, aVar, null) == aVar) {
if (this.loginReq != null) {
Properties properties = new Properties();
properties.setProperty(C0484a.y, this.loginReq.getCid());
C0484a.a(this.context).b(properties);
}
this.heartAlarm.a(this.context);
if (this.uuSdpTunnel != null) {
this.uuSdpTunnel = null;
}
this.loginReq = null;
this.loginRsp = null;
this.heartRsp = null;
this.heartReqProperties.clear();
q0.c("SafeLink", "Logout success,tunnel closed", new Object[0]);
if (uUSdpLogoutCallback != null) {
uUSdpLogoutCallback.onSuccess();
return;
}
return;
}
if (uUSdpLogoutCallback != null) {
uUSdpLogoutCallback.onError(102);
}
q0.b("SafeLink", "closeTunnel error SDP_TUNNEL_ERROR:102", new Object[0]);
} catch (Exception e2) {
e2.printStackTrace();
q0.b("SafeLink", "closeTunnel error SDP_TUNNEL_ERROR:102", new Object[0]);
if (uUSdpLogoutCallback != null) {
uUSdpLogoutCallback.onError(102);
}
}
}
public void addGatewayInfoChangeListener(UUSdpGatewayInfoChangeListener uUSdpGatewayInfoChangeListener) {
if (uUSdpGatewayInfoChangeListener == null || this.uuSdpGatewayInfoChangeListeners.contains(uUSdpGatewayInfoChangeListener)) {
return;
}
this.uuSdpGatewayInfoChangeListeners.add(uUSdpGatewayInfoChangeListener);
}
public void addTunnelStateListener(UUSdpTunnelStateListener uUSdpTunnelStateListener) {
if (uUSdpTunnelStateListener != null) {
this.uuSdpTunnelStateListeners.add(uUSdpTunnelStateListener);
}
}
public void b() {
try {
Thread.sleep(1000L);
if (getSelfTunnelState() == 0) {
q0.c("SafeLink", "onStateChange Down,Countdown over tunnel close", new Object[0]);
q0.c("SafeLink", "UUSdpTunnelStateListener size:" + this.uuSdpTunnelStateListeners.size(), new Object[0]);
Iterator<UUSdpTunnelStateListener> it = this.uuSdpTunnelStateListeners.iterator();
while (it.hasNext()) {
it.next().onTunnelDown(this.tunnelCloseCode);
}
logoutInternal(null);
return;
}
q0.c("SafeLink", "onStateChange Down,Countdown over tunnel reopen", new Object[0]);
} catch (Exception e2) {
e2.printStackTrace();
}
}
public void backToApp(Activity activity) {
q0.c("SafeLink", "Login success back to third app", new Object[0]);
o1.a().b();
if (this.startThirdApp) {
o1.a().a(activity);
}
}
public Boolean c() throws Exception {
return Boolean.valueOf(reStartInternal());
}
public void checkAllowApps(String str) {
if (this.backend == null) {
q0.c("SafeLink", "checkAllowApps backend is null" + str, new Object[0]);
return;
}
q0.c("SafeLink", "checkAllowApps pkgName ==" + str + "=backend.getUnInstallAppList()=" + this.backend.c().toString(), new Object[0]);
if (this.backend.c().contains(str)) {
reStart();
}
}
public void checkHeart() {
if (getTunnelState() == 0 && this.reConnect) {
sign(new f());
return;
}
long currentTimeMillis = System.currentTimeMillis();
if (currentTimeMillis - this.checkTime < 1000) {
return;
}
this.checkTime = currentTimeMillis;
long j = currentTimeMillis - this.lastHeartTime;
if (getSelfTunnelState() == 1) {
q0.d("SafeLink", "checkHeart start time diff = " + j, new Object[0]);
if (this.lastHeartTime <= 0 || j <= this.ht * 1000 * 2) {
return;
}
q0.d("SafeLink", "checkHeart reSend time diff = " + j, new Object[0]);
n0 n0Var = this.heartAlarm;
if (n0Var != null) {
n0Var.a(this.context);
}
n0 n0Var2 = new n0(new g(), this.context.getMainLooper(), this.context);
this.heartAlarm = n0Var2;
n0Var2.a(1000, this.context);
this.heartAlarm.a(this.ht * 1000);
}
}
public void clearGatewayInfoChangeListener() {
this.uuSdpGatewayInfoChangeListeners.clear();
}
public void clearTunnelStateListener() {
this.uuSdpTunnelStateListeners.clear();
}
public void enableDebugLog() {
q0.a(this.context, 1, m0.a(Environment.getExternalStorageDirectory(), DIR_APP, DIR_LOG).getAbsolutePath(), true);
}
public ArrayList<String> getAllowedApplications() {
s0 s0Var = this.uuSdpTunnel;
if (s0Var != null) {
return s0Var.a();
}
return null;
}
public ArrayList<AppPolicyDetail> getAppPolicyDetails() {
return this.appPolicyDetails;
}
public Activity getCurrentActivity() {
Activity activity = this.currentActivity;
if (activity != null) {
return activity;
}
Context context = this.context;
if (context == null || !(context instanceof Activity)) {
return null;
}
return (Activity) context;
}
public String getErrorMsg(int i) {
if (i == 101) {
return this.context.getString(R.string.uu_login_error_param);
}
if (i == 102) {
return this.context.getString(R.string.uu_login_error_102);
}
if (i == 103) {
return this.context.getString(R.string.uu_login_error_noresponse);
}
if (i == 104) {
return this.context.getString(R.string.uu_login_error_104);
}
if (i == 1001) {
return this.context.getString(R.string.uu_login_error_1001);
}
if (i == 1003) {
return this.context.getString(R.string.uu_login_error_1003);
}
if (i == 1004) {
return this.context.getString(R.string.uu_login_error_1004);
}
if (i == 1004) {
return this.context.getString(R.string.uu_login_error_1004);
}
if (i == 1005) {
return this.context.getString(R.string.uu_login_error_1005);
}
if (i == 1006) {
return this.context.getString(R.string.uu_login_error_1006);
}
if (i == 1007) {
return this.context.getString(R.string.uu_login_error_1007);
}
if (i == 1008) {
return this.context.getString(R.string.uu_login_error_1008);
}
if (i == 1009) {
return this.context.getString(R.string.uu_login_error_1009);
}
if (i == 1010) {
return this.context.getString(R.string.uu_login_error_1010);
}
if (i == 1011) {
return this.context.getString(R.string.uu_login_error_1011);
}
if (i == 1012) {
return this.context.getString(R.string.uu_login_error_1012);
}
if (i == 1013) {
return this.context.getString(R.string.uu_login_error_1013);
}
if (i == 1014) {
return this.context.getString(R.string.uu_login_error_1014);
}
if (i == 2002) {
return this.context.getString(R.string.uu_login_error_2002);
}
if (i == 2003) {
return this.context.getString(R.string.uu_login_error_2003);
}
if (i == 2004) {
return this.context.getString(R.string.uu_login_error_2004);
}
if (i == 2005) {
return this.context.getString(R.string.uu_login_error_2005);
}
if (i == 2006) {
return this.context.getString(R.string.uu_login_error_2006);
}
if (i == 2007) {
return this.context.getString(R.string.uu_login_error_2007);
}
if (i == 2008) {
return this.context.getString(R.string.uu_login_error_2008);
}
if (i == 2010) {
return this.context.getString(R.string.uu_login_error_2010);
}
if (i == 2011) {
return this.context.getString(R.string.uu_login_error_2011);
}
if (i == 2012) {
return this.context.getString(R.string.uu_login_error_2012);
}
if (i == 2013) {
return this.context.getString(R.string.uu_login_error_2013);
}
if (i == 2009) {
return this.context.getString(R.string.uu_login_error_2009);
}
if (i == 2019) {
return this.context.getString(R.string.uu_login_error_2019);
}
if (i == 2014) {
return this.context.getString(R.string.uu_login_error_2014);
}
if (i == 2015) {
return this.context.getString(R.string.uu_login_error_2015);
}
if (i == 2016) {
return this.context.getString(R.string.uu_login_error_2016);
}
if (i == 2017) {
return this.context.getString(R.string.uu_login_error_2017);
}
if (i == 2018) {
return this.context.getString(R.string.uu_login_error_2018);
}
if (i == 1021) {
return this.context.getString(R.string.uu_login_error_1021);
}
if (i == 1020) {
return this.context.getString(R.string.uu_login_error_1020);
}
if (i == 1022) {
return this.context.getString(R.string.uu_login_error_1022);
}
if (i == 1023) {
return this.context.getString(R.string.uu_login_error_1023);
}
return this.context.getString(R.string.uu_login_error_unknown) + " " + i;
}
public int getLastErrorCode() {
return this.lastErrorCode;
}
public int getSelfTunnelState() {
s0 s0Var = this.uuSdpTunnel;
return (s0Var != null && this.backend.a(s0Var) == u0.a.UP) ? 1 : 0;
}
public String getSt(String str) {
if (this.context.getPackageName().equals(str)) {
try {
C0493j c0493j = new C0493j();
StringBuffer stringBuffer = new StringBuffer();
Iterator<String> it = this.backend.f6359c.a().iterator();
while (it.hasNext()) {
stringBuffer.append(it.next());
stringBuffer.append(" ");
}
c0493j.setAllowedApplications(stringBuffer.toString());
StringBuffer stringBuffer2 = new StringBuffer();
for (g1 g1Var : this.backend.f6358b.a().a()) {
stringBuffer2.append(g1Var.toString());
stringBuffer2.append(" ");
}
c0493j.setAddress(stringBuffer2.toString());
StringBuffer stringBuffer3 = new StringBuffer();
for (InetAddress inetAddress : this.backend.f6358b.a().b()) {
stringBuffer3.append(inetAddress.toString());
stringBuffer3.append(" ");
}
c0493j.setDns(stringBuffer3.toString());
StringBuffer stringBuffer4 = new StringBuffer();
for (j1 j1Var : this.backend.f6358b.b()) {
for (g1 g1Var2 : j1Var.a()) {
stringBuffer4.append(g1Var2.toString());
stringBuffer4.append(" ");
}
}
c0493j.setAllowedIPs(stringBuffer4.toString());
StringBuffer stringBuffer5 = new StringBuffer();
for (j1 j1Var2 : this.backend.f6358b.b()) {
stringBuffer5.append(j1Var2.b().b().toString());
stringBuffer5.append(" ");
}
c0493j.setEndPoint(stringBuffer5.toString());
c0493j.setDnsHost(this.backend.f6359c.e());
return a0.a(b0.a(this.context.getPackageName()), new u1().a(c0493j));
} catch (Exception e2) {
e2.printStackTrace();
return "";
}
}
return "";
}
public String getToken() {
return C0484a.a(this.context).b();
}
public int getTunnelState() {
GoBackend goBackend;
s0 s0Var = this.uuSdpTunnel;
return ((s0Var == null || (goBackend = this.backend) == null || goBackend.a(s0Var) != u0.a.UP) && !checkSdpLogin()) ? 0 : 1;
}
public UUSdpEmmCallback getUuSdpEmmCallback() {
return this.uuSdpEmmCallback;
}
public VpnServiceBaseImpl getVpnServiceBase() {
return this.vpnServiceBase;
}
public void init(UUSdpInitInfo uUSdpInitInfo) {
q0.b("SafeLink", "init start params.ec=" + uUSdpInitInfo.getEc() + "params.host=" + uUSdpInitInfo.getHost() + "params.port=" + uUSdpInitInfo.getPort(), new Object[0]);
if (this.isZlogInit) {
q0.a(this.context, 2, m0.a(Environment.getExternalStorageDirectory(), DIR_APP, DIR_LOG).getAbsolutePath(), true);
}
q0.b("SafeLink", "init 2", new Object[0]);
if (this.backend == null) {
q0.b("SafeLink", "GoBackend init start", new Object[0]);
this.backend = new GoBackend(this.context);
q0.b("SafeLink", "GoBackend init over", new Object[0]);
registerActivityLifecycleCallbacks();
}
q0.b("SafeLink", "init 3", new Object[0]);
if (uUSdpInitInfo != null) {
C0484a.a(this.context).a(uUSdpInitInfo);
}
q0.b("SafeLink", "init 4 host=" + uUSdpInitInfo.getHost() + "=port=" + uUSdpInitInfo.getPort() + "=ec=" + uUSdpInitInfo.getEc(), new Object[0]);
this.heartReqProperties = new Properties();
}
public boolean isAutoLogin() {
return this.autoLogin;
}
public boolean isKickedByServer() {
return this.kickedByServer;
}
public boolean isMultipleSdk() {
return this.multipleSdk;
}
public boolean isStartThirdApp() {
return this.startThirdApp;
}
public boolean isV1() {
return this.v1;
}
public void login(UUSdpLoginRequestInfo uUSdpLoginRequestInfo, UUSdpLoginCallback uUSdpLoginCallback) {
q0.c("SafeLink", "UUSdpClient login called", new Object[0]);
if (this.uuSdpLoginCallback != null) {
q0.c("SafeLink", "UUSdpClient login not completed", new Object[0]);
} else if (!paramsCheck(uUSdpLoginRequestInfo)) {
q0.c("SafeLink", "paramsCheck error params.cid=" + uUSdpLoginRequestInfo.getCid(), new Object[0]);
loginError(101, null);
} else {
this.uuSdpLoginCallback = uUSdpLoginCallback;
loginInternal(uUSdpLoginRequestInfo);
}
}
public void logout(UUSdpLogoutCallback uUSdpLogoutCallback) {
q0.c("SafeLink", "UUSdpClient logout called", new Object[0]);
o1.a().a(this.context);
logoutInternal(uUSdpLogoutCallback);
}
public void modifyPassword(UUSdpModifyPasswordRequestInfo uUSdpModifyPasswordRequestInfo, UUSdpModifyPasswordCallback uUSdpModifyPasswordCallback) {
try {
C0484a.a(this.context).a(uUSdpModifyPasswordRequestInfo, new c(this, uUSdpModifyPasswordCallback));
} catch (Exception unused) {
uUSdpModifyPasswordCallback.onError(110);
}
}
@Override
public void onNetChange(int i) {
List<InetAddress> b2;
if ((this.heartRsp == null && this.loginRsp == null) || getSelfTunnelState() == 0 || (b2 = l0.b(this.context)) == null || b2.size() == 0) {
return;
}
List<InetAddress> list = this.currentDnsServers;
if (list != null && list.size() == b2.size()) {
boolean z = false;
for (int i2 = 0; i2 < this.currentDnsServers.size(); i2++) {
if (!this.currentDnsServers.get(i2).getHostAddress().equals(b2.get(i2).getHostAddress())) {
z = true;
}
}
if (!z) {
q0.c("SafeLink", "onNetChange dns not changed", new Object[0]);
return;
}
}
this.currentDnsServers.clear();
this.currentDnsServers.addAll(b2);
q0.c("SafeLink", "onNetChange dns changed", new Object[0]);
C0492i c0492i = null;
try {
r rVar = this.heartRsp;
if (rVar != null) {
c0492i = rVar.getData().getSc();
} else {
s sVar = this.loginRsp;
if (sVar != null) {
c0492i = sVar.getData().getSc();
}
}
if (c0492i != null) {
checkSecurity(c0492i);
}
} catch (Exception unused) {
q0.b("SafeLink", "onNetChange SecurityConfig wifi Exception", new Object[0]);
}
try {
x0 x0Var = new x0();
for (InetAddress inetAddress : b2) {
if (inetAddress.getHostAddress().indexOf(".") > 0) {
if (x0Var.getIpv4Preferred() == null) {
x0Var.setIpv4Preferred(inetAddress.getHostAddress());
} else if (x0Var.getIpv4Alternate() == null) {
x0Var.setIpv4Alternate(inetAddress.getHostAddress());
}
}
}
String a2 = new u1().a(x0Var);
q0.a("SafeLink", "onNetChange DnsServer " + a2, new Object[0]);
GoBackend.wgSetDNSServer(this.backend.b(), a2);
} catch (Exception e2) {
q0.a("SafeLink", e2);
q0.b("SafeLink", "onNetChange Dns set Exception", new Object[0]);
}
}
@Override
public void onStateChange(u0.a aVar) {
if (aVar == u0.a.UP) {
Iterator<UUSdpTunnelStateListener> it = this.uuSdpTunnelStateListeners.iterator();
while (it.hasNext()) {
it.next().onTunnelUp();
}
} else if (aVar == u0.a.DOWN) {
q0.c("SafeLink", "onStateChange Down,Countdown start", new Object[0]);
new Thread(new Runnable() {
@Override
public final void run() {
UUSdpClient.this.b();
}
}).start();
}
}
public boolean reStart() {
q0.c("SafeLink", "Tunnel reStart called", new Object[0]);
FutureTask futureTask = new FutureTask(new Callable() {
@Override
public final Object call() {
return UUSdpClient.this.c();
}
});
new Thread(futureTask).start();
try {
boolean booleanValue = ((Boolean) futureTask.get(5L, TimeUnit.SECONDS)).booleanValue();
q0.c("SafeLink", "Tunnel reStart result=" + booleanValue, new Object[0]);
return booleanValue;
} catch (Exception e2) {
q0.c("SafeLink", "Tunnel reStart Exception " + e2.getMessage(), new Object[0]);
return false;
}
}
public void refreshSms(UUSdpRefreshSmsRequestInfo uUSdpRefreshSmsRequestInfo, UUSdpRefreshSmsCallback uUSdpRefreshSmsCallback) {
try {
C0484a.a(this.context).a(uUSdpRefreshSmsRequestInfo, new d(this, uUSdpRefreshSmsCallback));
} catch (Exception unused) {
uUSdpRefreshSmsCallback.onError(110);
}
}
public void registerActivityLifecycleCallbacks() {
Application a2 = a.a.b.a.a();
if (a2 == null) {
q0.b("SafeLink", "registerActivityLifecycleCallbacks application==null", new Object[0]);
} else {
a2.registerActivityLifecycleCallbacks(new a());
}
}
public void registerNetWorkStateReceiver() {
if (this.uuNetWorkStateReceiver == null) {
this.uuNetWorkStateReceiver = new r0();
}
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
this.context.registerReceiver(this.uuNetWorkStateReceiver, intentFilter);
this.uuNetWorkStateReceiver.a(this);
}
public void removeGatewayInfoChangeListener(UUSdpGatewayInfoChangeListener uUSdpGatewayInfoChangeListener) {
if (uUSdpGatewayInfoChangeListener != null) {
this.uuSdpGatewayInfoChangeListeners.remove(uUSdpGatewayInfoChangeListener);
}
}
public void removeTunnelStateListener(UUSdpTunnelStateListener uUSdpTunnelStateListener) {
if (uUSdpTunnelStateListener != null) {
this.uuSdpTunnelStateListeners.remove(uUSdpTunnelStateListener);
}
}
public void setAutoLogin(boolean z) {
this.autoLogin = z;
}
public void setCurrentActivity(Activity activity) {
this.currentActivity = activity;
}
public void setKickedByServer(boolean z) {
this.kickedByServer = z;
}
public void setMultipleSdk(boolean z) {
this.multipleSdk = z;
}
public void setReConnect(boolean z) {
this.reConnect = z;
}
public void setStartThirdApp(boolean z) {
this.startThirdApp = z;
}
public void setUuSdpEmmCallback(UUSdpEmmCallback uUSdpEmmCallback) {
this.uuSdpEmmCallback = uUSdpEmmCallback;
}
public void setWgLog(boolean z) {
GoBackend goBackend = this.backend;
if (goBackend != null) {
goBackend.a(z);
}
}
public void setZlogInit(boolean z) {
this.isZlogInit = z;
}
public void sign(UUSdpLoginCallback uUSdpLoginCallback) {
String ticket = PreferenceUtils.getTicket(this.context);
String cid = PreferenceUtils.getCid(this.context);
if (ticket != null && ticket.length() != 0 && cid != null && cid.length() == 32) {
UUSdpLoginRequestInfo uUSdpLoginRequestInfo = new UUSdpLoginRequestInfo();
uUSdpLoginRequestInfo.setCid(cid);
uUSdpLoginRequestInfo.setPassword(ticket);
uUSdpLoginRequestInfo.setType(7);
uUSdpLoginRequestInfo.setSdpName(DIR_LOG);
uUSdpLoginRequestInfo.setAlgorithm(0);
login(uUSdpLoginRequestInfo, uUSdpLoginCallback);
return;
}
uUSdpLoginCallback.onError(111, new UUSdpLoginResponseInfo());
}
public void unregisterNetWorkStateReceiver() {
this.context.unregisterReceiver(this.uuNetWorkStateReceiver);
this.uuNetWorkStateReceiver = null;
}
public boolean web_enable() {
return false;
}
public class e implements f0 {
public e() {
}
@Override
public void a(r rVar) {
if (rVar != null) {
q0.c("SafeLink", "received heartBeat response", new Object[0]);
UUSdpClient.this.processHeartRsp(rVar);
return;
}
q0.b("SafeLink", "heartBeat no response", new Object[0]);
}
@Override
public void a(int i, int i2) {
UUSdpClient.this.lastErrorCode = i2;
q0.b("SafeLink", "heartBeat error ,errorCode:" + i2 + "=code=" + i, new Object[0]);
try {
if (!UUSdpClient.this.autoLogin || i != 1000 || (i2 != 10004 && i2 != 10001 && i2 != -1)) {
UUSdpClient.this.tunnelCloseCode = 1000;
} else {
q0.b("SafeLink", "heartBeat autoLogin", new Object[0]);
UUSdpClient.this.setKickedByServer(true);
}
if (i == 1000) {
UUSdpClient.this.backend.b(UUSdpClient.this.uuSdpTunnel, u0.a.DOWN, null);
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
public class b implements g0 {
public final String f6337a;
public final UUSdpLoginRequestInfo f6338b;
public b(String str, UUSdpLoginRequestInfo uUSdpLoginRequestInfo) {
this.f6337a = str;
this.f6338b = uUSdpLoginRequestInfo;
}
@Override
public void a(C0497n c0497n, s sVar) {
q0.c("SafeLink", "login onSuccess", new Object[0]);
UUSdpClient.this.processLoginRsp(this.f6337a, this.f6338b.getAlgorithm(), this.f6338b.getAllowedApplications(), c0497n, sVar, UUSdpClient.this.uuSdpLoginCallback);
if (sVar.getData().getV() == 1) {
UUSdpClient.this.v1 = true;
} else {
UUSdpClient.this.v1 = false;
}
PreferenceUtils.setTicket(sVar.getData().getTicket(), UUSdpClient.this.context);
PreferenceUtils.setCid(this.f6338b.getCid(), UUSdpClient.this.context);
}
@Override
public void a(int i, s sVar) {
q0.c("SafeLink", "Login error:" + i, new Object[0]);
if (i == 103) {
UUSdpClient.this.loginError(103, null);
return;
}
if (i == 1002) {
o1.a().a(UUSdpClient.this.context, this.f6338b);
} else {
PreferenceUtils.clearSsoData(UUSdpClient.this.context);
}
if (sVar != null) {
UUSdpClient.this.loginError(i, UUSdpClient.this.generateLoginResponseInfo(sVar));
return;
}
UUSdpClient.this.loginError(i, null);
}
}
public void a() {
this.currentDnsServers = l0.b(this.context);
}
public void a(String str, s sVar, ArrayList arrayList, String str2, int i) {
String str3;
try {
d1 a2 = d1.a(new ByteArrayInputStream(str.getBytes("UTF-8")));
String dnsSettings = getDnsSettings(sVar);
q0.c("SafeLink", "openTunnel->dnsSettings==" + dnsSettings + "=endpoint=" + a2.b().get(0).b().toString(), new Object[0]);
arrayList.clear();
if (sVar.getData().getAaf() == 1) {
ArrayList<AppPolicyDetail> apds = sVar.getData().getApds();
String a3 = new u1().a(apds);
if (apds != null && (apds instanceof List)) {
for (AppPolicyDetail appPolicyDetail : apds) {
if (appPolicyDetail.getPkn() != null) {
arrayList.add(appPolicyDetail.getPkn());
this.appPolicyDetails.add(appPolicyDetail);
}
}
}
str3 = a3;
} else {
str3 = "";
}
q0.d("SafeLink", "openTunnel-> allowedApplications==" + arrayList.toString(), new Object[0]);
s0 s0Var = new s0(str2, a2, u0.a.DOWN, i, dnsSettings, arrayList, str3);
this.uuSdpTunnel = s0Var;
s0Var.a(this);
this.uuSdpTunnel.a(sVar.getData().getDf());
this.uuSdpTunnel.c(sVar.getData().getDt());
GoBackend goBackend = this.backend;
s0 s0Var2 = this.uuSdpTunnel;
u0.a aVar = u0.a.UP;
if (goBackend.b(s0Var2, aVar, s0Var2.g()) == aVar) {
q0.c("SafeLink", "openTunnel->Login success,tunnel open", new Object[0]);
try {
UUSdpLoginResponseInfo generateLoginResponseInfo = generateLoginResponseInfo(sVar);
setHeartBeatListener();
q0.d("SafeLink", "openTunnel-> generateHeartProperties", new Object[0]);
generateHeartProperties(null);
this.lastHeartTime = System.currentTimeMillis();
startAlarm();
q0.c("SafeLink", "openTunnel->Login success,loginCallback", new Object[0]);
final ArrayList<UUSdpGatewayInfo> gis = generateLoginResponseInfo.getGis();
if (gis == null || gis.size() <= 0) {
return;
}
VpnServiceBaseImpl vpnServiceBase = getInstance(this.context).getVpnServiceBase();
if (vpnServiceBase != null) {
vpnServiceBase.getNetguard();
}
new Thread(new Runnable() {
@Override
public final void run() {
z0.a(((UUSdpGatewayInfo) gis.get(0)).getIp(), 5);
}
}).start();
loginSuccess(generateLoginResponseInfo);
backToApp(getCurrentActivity());
return;
} catch (Exception e2) {
q0.b("SafeLink", "openTunnel->UUSdpClient login generateLoginResponseInfo fail" + e2.getMessage(), new Object[0]);
loginError(t0.a.SDP_CLIENT_LOGIN_SETSTATE_FAIL.getCode(), null);
return;
}
}
q0.b("SafeLink", "openTunnel->UUSdpClient login setState fail:", new Object[0]);
loginError(t0.a.SDP_CLIENT_LOGIN_SETSTATE_FAIL.getCode(), null);
} catch (Exception e3) {
q0.a("SafeLink", e3);
q0.b("SafeLink", "openTunnel->UUSdpClient login openTunnel exception:" + e3.getMessage(), new Object[0]);
if (e3 instanceof t0) {
loginError(((t0) e3).getReason().getCode(), null);
} else {
loginError(110, null);
}
}
}
private String getDnsSettings(r rVar) {
try {
y0 y0Var = new y0();
x0 x0Var = new x0();
for (InetAddress inetAddress : l0.b(this.context)) {
if (inetAddress.getHostAddress().indexOf(".") > 0) {
if (x0Var.getIpv4Preferred() == null) {
x0Var.setIpv4Preferred(inetAddress.getHostAddress());
} else if (x0Var.getIpv4Alternate() == null) {
x0Var.setIpv4Alternate(inetAddress.getHostAddress());
}
}
}
y0Var.setServer(x0Var);
w0 w0Var = new w0();
if (x0Var.getIpv4Preferred() != null) {
w0Var.setIpv4Preferred("198.51.100.1");
}
if (x0Var.getIpv4Alternate() != null) {
w0Var.setIpv4Alternate("10.255.255.255");
}
y0Var.setRoute(w0Var);
C0486c[] dns = rVar.getData().getDns();
int length = dns.length;
v0[] v0VarArr = new v0[length];
for (int i = 0; i < length; i++) {
C0486c c0486c = dns[i];
v0 v0Var = new v0();
v0Var.setName(c0486c.getName());
v0Var.setIpv4(c0486c.getIpv4());
v0Var.setIpv6(c0486c.getIpv6());
v0VarArr[i] = v0Var;
}
y0Var.setHosts(v0VarArr);
return new u1().a(y0Var);
} catch (Exception unused) {
return "";
}
}
}