Proxy Master v3.4.9版本的 MD5 值为:14d0aa2468d13530c8f6e96bcc114bf5
以下内容为反编译后的 CharonVpnService.java 源代码,内容仅作参考
package com.free.vpn.strongswan.logic;
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.VpnService;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.ParcelFileDescriptor;
import android.security.KeyChain;
import android.system.OsConstants;
import android.text.TextUtils;
import androidx.activity.d;
import androidx.activity.k;
import androidx.annotation.Keep;
import com.free.vpn.strongswan.R$color;
import com.free.vpn.strongswan.R$drawable;
import com.free.vpn.strongswan.R$string;
import com.free.vpn.strongswan.data.VpnProfile;
import com.free.vpn.strongswan.data.VpnType;
import com.free.vpn.strongswan.logic.VpnStateService;
import com.free.vpn.strongswan.utils.StrongSwanUtils;
import com.free.vpn.strongswan.utils.b;
import com.unity3d.ads.core.data.datasource.AndroidStaticDeviceInfoDataSource;
import io.appmetrica.analytics.coreutils.internal.StringUtils;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedByInterruptException;
import java.security.PrivateKey;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;
import java.util.SortedSet;
import java.util.TreeSet;
import n7.e;
import r7.h;
import u.q;
import v.b;
import ye.g0;
import z7.b;
@Keep
public class CharonVpnService extends VpnService implements Runnable, VpnStateService.g, b.a {
public static final String CONNECT_ACTION = "com.supervpn.vpn.strongswan.CharonVpnService.CONNECT";
public static final String DISCONNECT_ACTION = "com.supervpn.vpn.strongswan.CharonVpnService.DISCONNECT";
public static final String KEY_IS_RETRY = "retry";
public static String LOG_FILE = "ss.log";
static final int STATE_AUTH_ERROR = 3;
static final int STATE_CERTIFICATE_UNAVAILABLE = 7;
static final int STATE_CHILD_SA_DOWN = 2;
static final int STATE_CHILD_SA_UP = 1;
static final int STATE_GENERIC_ERROR = 8;
static final int STATE_LOOKUP_ERROR = 5;
static final int STATE_PEER_AUTH_ERROR = 4;
static final int STATE_UNREACHABLE_ERROR = 6;
private static final String TAG = "CharonVpnService";
public static final int VPN_STATE_NOTIFICATION_ID = 199;
private static String f7004a;
public static String appPkgName;
public static Intent launcherIntent;
private Bitmap appIconBitmap;
private String appName;
private String currentCountryCode;
private String currentCountryName;
private String mAppDir;
private Thread mConnectionHandler;
private volatile String mCurrentCertificateAlias;
private VpnProfile mCurrentProfile;
private volatile String mCurrentUserCertificateAlias;
private Handler mHandler;
private volatile boolean mIsDisconnecting;
private String mLogFile;
private VpnProfile mNextProfile;
private volatile boolean mProfileUpdated;
private VpnStateService mService;
private volatile boolean mShowNotification;
private volatile boolean mTerminate;
private final BuilderAdapter mBuilderAdapter = new BuilderAdapter();
private final Object mServiceLock = new Object();
private final String packageName = r7.a.d();
private final ServiceConnection mServiceConnection = new a();
@Keep
public class BuilderAdapter {
private VpnService.Builder mBuilder;
private b mCache;
private a mDropper = new a();
private b mEstablishedCache;
private VpnProfile mProfile;
public class a implements Runnable {
public ParcelFileDescriptor f7005b;
public Thread f7006c;
public a() {
BuilderAdapter.this = r1;
}
@Override
public final synchronized void run() {
int read;
try {
FileInputStream fileInputStream = new FileInputStream(this.f7005b.getFileDescriptor());
ByteBuffer allocate = ByteBuffer.allocate(BuilderAdapter.this.mCache.f7019k);
do {
read = fileInputStream.getChannel().read(allocate);
allocate.clear();
} while (read >= 0);
} catch (IOException e10) {
e10.printStackTrace();
} catch (InterruptedException | ClosedByInterruptException unused) {
}
}
}
public BuilderAdapter() {
CharonVpnService.this = r1;
}
private VpnService.Builder createBuilder(String str) {
VpnService.Builder builder = new VpnService.Builder(CharonVpnService.this);
builder.setSession(str);
Context applicationContext = CharonVpnService.this.getApplicationContext();
Intent intent = new Intent();
intent.setPackage(CharonVpnService.this.packageName);
intent.setAction("android.intent.action.VIEW");
builder.setConfigureIntent(PendingIntent.getActivity(applicationContext, 0, intent, 201326592));
return builder;
}
private synchronized ParcelFileDescriptor establishIntern() {
try {
this.mCache.c(this.mBuilder);
ParcelFileDescriptor establish = this.mBuilder.establish();
if (establish != null) {
closeBlocking();
}
if (establish == null) {
return null;
}
this.mBuilder = createBuilder(this.mProfile.getName());
this.mEstablishedCache = this.mCache;
this.mCache = new b(this.mProfile);
return establish;
} catch (Exception e10) {
e10.printStackTrace();
return null;
}
}
public synchronized boolean addAddress(String str, int i10) {
try {
this.mCache.a(i10, str);
} catch (IllegalArgumentException unused) {
return false;
}
return true;
}
public synchronized boolean addDnsServer(String str) {
try {
b bVar = this.mCache;
if (!bVar.f7022n) {
try {
bVar.f7018j.add(StrongSwanUtils.parseInetAddress(str));
bVar.d(str);
} catch (UnknownHostException e10) {
e10.printStackTrace();
}
}
} catch (IllegalArgumentException unused) {
return false;
}
return true;
}
public synchronized boolean addRoute(String str, int i10) {
try {
this.mCache.b(i10, str);
} catch (IllegalArgumentException unused) {
return false;
}
return true;
}
public synchronized boolean addSearchDomain(String str) {
try {
this.mBuilder.addSearchDomain(str);
} catch (IllegalArgumentException unused) {
return false;
}
return true;
}
public synchronized void closeBlocking() {
a aVar = this.mDropper;
if (aVar.f7005b != null) {
try {
aVar.f7006c.interrupt();
aVar.f7006c.join();
aVar.f7005b.close();
} catch (IOException e10) {
e10.printStackTrace();
} catch (InterruptedException e11) {
e11.printStackTrace();
}
aVar.f7005b = null;
}
}
public synchronized int establish() {
ParcelFileDescriptor establishIntern;
establishIntern = establishIntern();
return establishIntern != null ? establishIntern.detachFd() : -1;
}
@TargetApi(21)
public synchronized void establishBlocking() {
this.mCache.a(32, "172.16.252.1");
this.mCache.a(128, "fd00::fd02:1");
this.mCache.b(0, "0.0.0.0");
this.mCache.b(0, "::");
this.mBuilder.addDnsServer("8.8.8.8");
this.mBuilder.addDnsServer("2001:4860:4860::8888");
this.mBuilder.setBlocking(true);
ParcelFileDescriptor establishIntern = establishIntern();
if (establishIntern != null) {
a aVar = this.mDropper;
aVar.f7005b = establishIntern;
Thread thread = new Thread(aVar);
aVar.f7006c = thread;
thread.start();
}
}
public synchronized int establishNoDns() {
if (this.mEstablishedCache == null) {
return -1;
}
try {
VpnService.Builder createBuilder = createBuilder(this.mProfile.getName());
this.mEstablishedCache.c(createBuilder);
ParcelFileDescriptor establish = createBuilder.establish();
if (establish == null) {
return -1;
}
return establish.detachFd();
} catch (Exception e10) {
e10.printStackTrace();
return -1;
}
}
public synchronized boolean setMtu(int i10) {
try {
this.mCache.f7019k = i10;
} catch (IllegalArgumentException unused) {
return false;
}
return true;
}
public synchronized void setProfile(VpnProfile vpnProfile) {
this.mProfile = vpnProfile;
this.mBuilder = createBuilder(vpnProfile.getName());
this.mCache = new b(this.mProfile);
}
}
public class a implements ServiceConnection {
public a() {
CharonVpnService.this = r1;
}
@Override
public final void onServiceConnected(ComponentName componentName, IBinder iBinder) {
synchronized (CharonVpnService.this.mServiceLock) {
CharonVpnService.this.mService = VpnStateService.this;
}
CharonVpnService.this.mService.registerListener(CharonVpnService.this);
CharonVpnService.this.mConnectionHandler.start();
}
@Override
public final void onServiceDisconnected(ComponentName componentName) {
synchronized (CharonVpnService.this.mServiceLock) {
CharonVpnService.this.mService = null;
}
}
}
public class b {
public final com.free.vpn.strongswan.utils.c f7014f;
public final int f7015g;
public final VpnProfile.a f7016h;
public final SortedSet<String> f7017i;
public int f7019k;
public boolean f7020l;
public boolean f7021m;
public final boolean f7022n;
public final ArrayList f7009a = new ArrayList();
public final ArrayList f7010b = new ArrayList();
public final ArrayList f7011c = new ArrayList();
public final com.free.vpn.strongswan.utils.c f7012d = new com.free.vpn.strongswan.utils.c();
public final com.free.vpn.strongswan.utils.c f7013e = new com.free.vpn.strongswan.utils.c();
public final ArrayList f7018j = new ArrayList();
public b(VpnProfile vpnProfile) {
String[] split;
Iterator<com.free.vpn.strongswan.utils.a> it = com.free.vpn.strongswan.utils.c.c(vpnProfile.getIncludedSubnets()).iterator();
while (it.hasNext()) {
com.free.vpn.strongswan.utils.a next = it.next();
if (next.g() instanceof Inet4Address) {
this.f7012d.b(next);
} else if (next.g() instanceof Inet6Address) {
this.f7013e.b(next);
}
}
this.f7014f = com.free.vpn.strongswan.utils.c.c(vpnProfile.getExcludedSubnets());
Integer splitTunneling = vpnProfile.getSplitTunneling();
this.f7015g = splitTunneling != null ? splitTunneling.intValue() : 0;
VpnProfile.a selectedAppsHandling = vpnProfile.getSelectedAppsHandling();
SortedSet<String> selectedAppsSet = vpnProfile.getSelectedAppsSet();
this.f7017i = selectedAppsSet;
if (selectedAppsHandling.ordinal() == 0) {
selectedAppsHandling = VpnProfile.a.SELECTED_APPS_EXCLUDE;
selectedAppsSet.clear();
}
this.f7016h = selectedAppsHandling;
if (vpnProfile.getDnsServers() != null) {
for (String str : vpnProfile.getDnsServers().split("\\s+")) {
try {
this.f7018j.add(StrongSwanUtils.parseInetAddress(str));
d(str);
this.f7022n = true;
} catch (UnknownHostException e10) {
e10.printStackTrace();
}
}
}
Integer mtu = vpnProfile.getMTU();
this.f7019k = mtu == null ? 1500 : mtu.intValue();
}
public final void a(int i10, String str) {
try {
this.f7009a.add(new com.free.vpn.strongswan.utils.a(str, i10));
d(str);
} catch (UnknownHostException e10) {
e10.printStackTrace();
}
}
public final void b(int i10, String str) {
try {
InetAddress parseInetAddress = StrongSwanUtils.parseInetAddress(str);
boolean z6 = false;
if (!(parseInetAddress instanceof Inet4Address) && (parseInetAddress instanceof Inet6Address)) {
z6 = true;
}
this.f7010b.add(new com.free.vpn.strongswan.utils.a(str, i10));
} catch (UnknownHostException e10) {
e10.printStackTrace();
}
}
@TargetApi(21)
public final void c(VpnService.Builder builder) {
Iterator it = this.f7009a.iterator();
while (it.hasNext()) {
com.free.vpn.strongswan.utils.a aVar = (com.free.vpn.strongswan.utils.a) it.next();
builder.addAddress(aVar.g(), aVar.f7057e.intValue());
}
Iterator it2 = this.f7018j.iterator();
while (it2.hasNext()) {
builder.addDnsServer((InetAddress) it2.next());
}
int i10 = this.f7015g;
int i11 = i10 & 1;
com.free.vpn.strongswan.utils.c cVar = this.f7014f;
if (i11 == 0) {
if (this.f7020l) {
com.free.vpn.strongswan.utils.c cVar2 = new com.free.vpn.strongswan.utils.c();
com.free.vpn.strongswan.utils.c cVar3 = this.f7012d;
if (cVar3.f7061b.size() <= 0) {
Iterator it3 = this.f7010b.iterator();
while (it3.hasNext()) {
cVar2.b((com.free.vpn.strongswan.utils.a) it3.next());
}
} else if (cVar3 != cVar2) {
Iterator<com.free.vpn.strongswan.utils.a> it4 = cVar3.f7061b.iterator();
while (it4.hasNext()) {
cVar2.b(it4.next());
}
}
cVar2.d(cVar);
b.a aVar2 = new b.a(new com.free.vpn.strongswan.utils.b(cVar2));
while (aVar2.hasNext()) {
com.free.vpn.strongswan.utils.a aVar3 = (com.free.vpn.strongswan.utils.a) aVar2.next();
try {
builder.addRoute(aVar3.g(), aVar3.f7057e.intValue());
} catch (IllegalArgumentException e10) {
if (!aVar3.g().isMulticastAddress()) {
throw e10;
}
}
}
} else {
builder.allowFamily(OsConstants.AF_INET);
}
} else if (this.f7020l) {
builder.addRoute("0.0.0.0", 0);
}
if ((i10 & 2) == 0) {
if (this.f7021m) {
com.free.vpn.strongswan.utils.c cVar4 = new com.free.vpn.strongswan.utils.c();
com.free.vpn.strongswan.utils.c cVar5 = this.f7013e;
if (cVar5.f7061b.size() <= 0) {
Iterator it5 = this.f7011c.iterator();
while (it5.hasNext()) {
cVar4.b((com.free.vpn.strongswan.utils.a) it5.next());
}
} else if (cVar5 != cVar4) {
Iterator<com.free.vpn.strongswan.utils.a> it6 = cVar5.f7061b.iterator();
while (it6.hasNext()) {
cVar4.b(it6.next());
}
}
cVar4.d(cVar);
b.a aVar4 = new b.a(new com.free.vpn.strongswan.utils.b(cVar4));
while (aVar4.hasNext()) {
com.free.vpn.strongswan.utils.a aVar5 = (com.free.vpn.strongswan.utils.a) aVar4.next();
try {
builder.addRoute(aVar5.g(), aVar5.f7057e.intValue());
} catch (IllegalArgumentException e11) {
if (!aVar5.g().isMulticastAddress()) {
throw e11;
}
}
}
} else {
builder.allowFamily(OsConstants.AF_INET6);
}
} else if (this.f7021m) {
builder.addRoute("::", 0);
}
SortedSet<String> sortedSet = this.f7017i;
if (sortedSet.size() > 0) {
int ordinal = this.f7016h.ordinal();
if (ordinal == 1) {
for (String str : sortedSet) {
try {
builder.addDisallowedApplication(str);
} catch (PackageManager.NameNotFoundException unused) {
}
}
} else if (ordinal == 2) {
for (String str2 : sortedSet) {
try {
builder.addAllowedApplication(str2);
} catch (PackageManager.NameNotFoundException unused2) {
}
}
}
}
builder.setMtu(this.f7019k);
}
public final void d(String str) {
try {
InetAddress parseInetAddress = StrongSwanUtils.parseInetAddress(str);
boolean z6 = false;
if (!(parseInetAddress instanceof Inet4Address) && (parseInetAddress instanceof Inet6Address)) {
z6 = true;
}
this.f7020l = true;
} catch (UnknownHostException e10) {
e10.printStackTrace();
}
}
}
static {
System.loadLibrary("androidbridge");
appPkgName = r7.a.d();
launcherIntent = null;
}
public static void a(CharonVpnService charonVpnService) {
charonVpnService.lambda$addNotification$0();
}
private void addNotification() {
this.mHandler.post(new d(this, 11));
}
public static void b(CharonVpnService charonVpnService) {
charonVpnService.lambda$removeNotification$1();
}
private Notification buildConnectedNetworkNotification(String str) {
q qVar = new q(this, "myvpn_bg");
qVar.f35138z.icon = R$drawable.ic_notification;
qVar.f35123k = true;
qVar.f35130r = "service";
qVar.f35133u = 1;
qVar.e(2, true);
qVar.f35122j = 2;
qVar.d(getString(R$string.notify_network_speed_title, this.currentCountryName));
qVar.c(str);
int i10 = R$color.success_text;
Object obj = v.b.f35534a;
qVar.f35132t = b.d.a(this, i10);
Bitmap bitmap = this.appIconBitmap;
if (bitmap != null && !bitmap.isRecycled()) {
qVar.f(this.appIconBitmap);
}
qVar.f35119g = PendingIntent.getActivity(getApplicationContext(), 0, getLauncherIntent(), 201326592);
return qVar.a();
}
private Notification buildNotification(boolean z6) {
VpnStateService.b bVar;
VpnStateService.f fVar = VpnStateService.f.DISABLED;
VpnStateService.b bVar2 = VpnStateService.b.NO_ERROR;
VpnStateService vpnStateService = this.mService;
if (vpnStateService != null) {
fVar = vpnStateService.getState();
bVar = this.mService.getErrorState();
} else {
bVar = bVar2;
}
q qVar = new q(this, "myvpn_bg");
qVar.f35138z.icon = R$drawable.ic_notification;
qVar.f35123k = true;
qVar.f35130r = "service";
qVar.f35133u = z6 ? 1 : 0;
qVar.e(2, true);
qVar.d(r7.a.c());
if (bVar != bVar2) {
int i10 = R$color.error_text;
Object obj = v.b.f35534a;
qVar.f35132t = b.d.a(this, i10);
qVar.d(getString(R$string.notify_is_off_title, this.appName));
qVar.c(getString(R$string.notify_is_off_content));
} else {
int ordinal = fVar.ordinal();
if (ordinal == 1) {
qVar.c(getString(R$string.vpn_state_connecting));
int i11 = R$color.warning_text;
Object obj2 = v.b.f35534a;
qVar.f35132t = b.d.a(this, i11);
} else if (ordinal == 2) {
qVar.c(getString(R$string.vpn_state_connected));
int i12 = R$color.success_text;
Object obj3 = v.b.f35534a;
qVar.f35132t = b.d.a(this, i12);
qVar.f35124l = true;
} else if (ordinal != 3) {
int i13 = R$color.error_text;
Object obj4 = v.b.f35534a;
qVar.f35132t = b.d.a(this, i13);
qVar.d(getString(R$string.notify_is_off_title, r7.a.c()));
qVar.c(getString(R$string.notify_is_off_content));
} else {
qVar.c(getString(R$string.vpn_state_disconnecting));
int i14 = R$color.warning_text;
Object obj5 = v.b.f35534a;
qVar.f35132t = b.d.a(this, i14);
}
}
if (!z6) {
qVar.f35134v = buildNotification(true);
}
qVar.f35122j = 2;
qVar.f35119g = PendingIntent.getActivity(getApplicationContext(), 0, getLauncherIntent(), 201326592);
return qVar.a();
}
private static String getAndroidVersion() {
StringBuilder t10 = android.support.v4.media.b.t("Android " + Build.VERSION.RELEASE + " - " + Build.DISPLAY, "/");
t10.append(Build.VERSION.SECURITY_PATCH);
return t10.toString();
}
public static X509Certificate getCertificate() {
try {
if (TextUtils.isEmpty(f7004a)) {
return null;
}
return (X509Certificate) CertificateFactory.getInstance(AndroidStaticDeviceInfoDataSource.CERTIFICATE_TYPE_X509).generateCertificate(new ByteArrayInputStream(f7004a.getBytes()));
} catch (Exception e10) {
e10.printStackTrace();
return null;
}
}
private static String getDeviceString() {
return Build.MODEL + " - " + Build.BRAND + "/" + Build.PRODUCT + "/" + Build.MANUFACTURER;
}
public static Intent getLauncherIntent() {
if (launcherIntent == null) {
Intent intent = new Intent();
launcherIntent = intent;
intent.setAction("android.intent.action.VIEW");
launcherIntent.setPackage(appPkgName);
}
return launcherIntent;
}
private byte[][] getTrustedCertificates() {
ArrayList arrayList = new ArrayList();
TrustedCertificateManager load = TrustedCertificateManager.getInstance().load();
try {
String str = this.mCurrentCertificateAlias;
if (str != null) {
X509Certificate cACertificateFromAlias = load.getCACertificateFromAlias(str);
if (cACertificateFromAlias == null) {
return null;
}
arrayList.add(cACertificateFromAlias.getEncoded());
} else {
for (X509Certificate x509Certificate : load.getAllCACertificates().values()) {
arrayList.add(x509Certificate.getEncoded());
}
}
try {
arrayList.add(getCertificate().getEncoded());
} catch (Exception e10) {
e10.printStackTrace();
}
return (byte[][]) arrayList.toArray(new byte[arrayList.size()]);
} catch (CertificateEncodingException e11) {
e11.printStackTrace();
return null;
}
}
private byte[][] getUserCertificate() {
ArrayList arrayList = new ArrayList();
X509Certificate[] certificateChain = KeyChain.getCertificateChain(getApplicationContext(), this.mCurrentUserCertificateAlias);
if (certificateChain == null || certificateChain.length == 0) {
return null;
}
for (X509Certificate x509Certificate : certificateChain) {
arrayList.add(x509Certificate.getEncoded());
}
return (byte[][]) arrayList.toArray(new byte[arrayList.size()]);
}
private PrivateKey getUserKey() {
return KeyChain.getPrivateKey(getApplicationContext(), this.mCurrentUserCertificateAlias);
}
public void lambda$addNotification$0() {
this.mShowNotification = true;
startForeground(199, buildNotification(false));
g0.Y("start strongswan foreground service...", new Object[0]);
}
public void lambda$removeNotification$1() {
this.mShowNotification = false;
stopForeground(true);
g0.Y("stop strongswan foreground service...", new Object[0]);
}
private void removeNotification() {
this.mHandler.post(new k(this, 18));
}
private void setError(VpnStateService.b bVar) {
synchronized (this.mServiceLock) {
VpnStateService vpnStateService = this.mService;
if (vpnStateService != null) {
vpnStateService.setError(bVar);
}
}
}
private void setErrorDisconnect(VpnStateService.b bVar) {
synchronized (this.mServiceLock) {
if (this.mService != null && !this.mIsDisconnecting) {
this.mService.setError(bVar);
}
}
}
private void setNextProfile(VpnProfile vpnProfile) {
synchronized (this) {
this.mNextProfile = vpnProfile;
this.mProfileUpdated = true;
notifyAll();
}
}
private void setState(VpnStateService.f fVar) {
synchronized (this.mServiceLock) {
VpnStateService vpnStateService = this.mService;
if (vpnStateService != null) {
vpnStateService.setState(fVar);
}
}
}
private void startConnection(VpnProfile vpnProfile) {
synchronized (this.mServiceLock) {
VpnStateService vpnStateService = this.mService;
if (vpnStateService != null) {
vpnStateService.startConnection(vpnProfile);
}
}
}
private void stopCurrentConnection() {
synchronized (this) {
VpnProfile vpnProfile = this.mNextProfile;
if (vpnProfile != null) {
this.mBuilderAdapter.setProfile(vpnProfile);
this.mBuilderAdapter.establishBlocking();
}
if (this.mCurrentProfile != null) {
setState(VpnStateService.f.DISCONNECTING);
this.mIsDisconnecting = true;
SimpleFetcher.disable();
deinitializeCharon();
g0.Y("charon stopped", new Object[0]);
this.mCurrentProfile = null;
if (this.mNextProfile == null) {
removeNotification();
this.mBuilderAdapter.closeBlocking();
}
}
}
}
private void updateNetworkSpeed() {
VpnStateService.f fVar = VpnStateService.f.DISABLED;
VpnStateService vpnStateService = this.mService;
if (vpnStateService != null) {
fVar = vpnStateService.getState();
}
if (fVar != VpnStateService.f.CONNECTED) {
z7.b.d().getClass();
z7.b.e();
z7.b.h();
z7.b.d().f37449a.remove(this);
return;
}
z7.b d10 = z7.b.d();
d10.getClass();
long e10 = z7.b.e();
d10.f37450b = e10;
o7.a.i("key_start_rx_bytes", e10);
long h10 = z7.b.h();
d10.f37451c = h10;
o7.a.i("key_start_tx_bytes", h10);
z7.b.d().f37449a.add(this);
}
public native void deinitializeCharon();
public native boolean initializeCharon(BuilderAdapter builderAdapter, String str, String str2, boolean z6);
public native void initiate(String str);
@Override
public void onCreate() {
this.mLogFile = getFilesDir().getAbsolutePath() + File.separator + LOG_FILE;
this.mAppDir = getFilesDir().getAbsolutePath();
this.appName = r7.a.c();
this.appIconBitmap = h.a(r7.a.a());
this.mHandler = new Handler(Looper.getMainLooper());
this.mConnectionHandler = new Thread(this);
bindService(new Intent(this, VpnStateService.class), this.mServiceConnection, 1);
}
@Override
public void onDestroy() {
this.mTerminate = true;
setNextProfile(null);
try {
this.mConnectionHandler.join();
} catch (InterruptedException e10) {
e10.printStackTrace();
}
VpnStateService vpnStateService = this.mService;
if (vpnStateService != null) {
vpnStateService.unregisterListener(this);
unbindService(this.mServiceConnection);
}
try {
if (this.appIconBitmap.isRecycled()) {
return;
}
this.appIconBitmap.recycle();
} catch (Exception e11) {
e11.printStackTrace();
}
}
@Override
public void onRevoke() {
setNextProfile(null);
}
@Override
public int onStartCommand(Intent intent, int i10, int i11) {
VpnProfile vpnProfile;
if (intent != null) {
Bundle extras = intent.getExtras();
boolean z6 = false;
g0.Y("start chargon service... action = " + intent.getAction(), new Object[0]);
if (extras == null || TextUtils.equals(intent.getAction(), DISCONNECT_ACTION)) {
vpnProfile = null;
} else {
vpnProfile = new VpnProfile();
f7004a = extras.getString("llll1lll");
this.currentCountryName = extras.getString("ll1lllll");
this.currentCountryCode = extras.getString("lll1llll");
vpnProfile.setName(extras.getString("l1ll1l1l"));
vpnProfile.setGateway(extras.getString("lllllll1"));
vpnProfile.setUsername(extras.getString("l1ll1lll"));
vpnProfile.setPassword(extras.getString("lllll1ll"));
vpnProfile.setRemoteId(extras.getString("llllll1l"));
vpnProfile.setVpnType(VpnType.IKEV2_EAP);
vpnProfile.setPort(Integer.valueOf(extras.getInt("l1111l1l", 4500)));
boolean z9 = extras.getBoolean(KEY_IS_RETRY, false);
boolean b6 = e.b();
g0.Y("allowedAllApps = " + b6, new Object[0]);
if (b6) {
vpnProfile.setSelectedAppsHandling(VpnProfile.a.SELECTED_APPS_EXCLUDE);
vpnProfile.setSelectedApps(new TreeSet(g0.P()));
} else {
vpnProfile.setSelectedAppsHandling(VpnProfile.a.SELECTED_APPS_ONLY);
String e10 = o7.a.e("key_allow_app_list_2319");
if (!TextUtils.isEmpty(e10)) {
e10 = e10.replaceAll(StringUtils.COMMA, " ");
}
boolean a8 = o7.a.a("key_pg");
g0.Y("suggest pg = " + a8, new Object[0]);
if (a8) {
e10 = android.support.v4.media.b.l(e10, " com.google.android.gms");
}
boolean v7 = e.v();
g0.Y("suggest ps = " + v7, new Object[0]);
if (v7) {
StringBuilder t10 = android.support.v4.media.b.t(e10, " ");
t10.append(r7.a.d());
e10 = t10.toString();
}
vpnProfile.setSelectedApps(e10);
}
z6 = z9;
}
if (vpnProfile != null && !z6) {
deleteFile(LOG_FILE);
}
setNextProfile(vpnProfile);
return 2;
}
return 2;
}
@Override
public void onTrafficUpdate(String str, String str2, String str3, String str4) {
VpnStateService.f fVar = VpnStateService.f.DISABLED;
VpnStateService vpnStateService = this.mService;
if (vpnStateService != null) {
fVar = vpnStateService.getState();
}
if (fVar == VpnStateService.f.CONNECTED) {
((NotificationManager) getSystemService("notification")).notify(199, buildConnectedNetworkNotification(getString(R$string.network_speed_and_data, str3, str4, str, str2)));
}
}
@Override
public void onTrafficUpdate(z7.a aVar) {
}
@Override
public void run() {
while (true) {
synchronized (this) {
while (!this.mProfileUpdated) {
try {
wait();
} catch (InterruptedException unused) {
stopCurrentConnection();
setState(VpnStateService.f.DISABLED);
}
}
this.mProfileUpdated = false;
stopCurrentConnection();
VpnProfile vpnProfile = this.mNextProfile;
if (vpnProfile == null) {
setState(VpnStateService.f.DISABLED);
if (this.mTerminate) {
return;
}
} else {
this.mCurrentProfile = vpnProfile;
String str = null;
this.mNextProfile = null;
this.mCurrentCertificateAlias = vpnProfile.getCertificateAlias();
this.mCurrentUserCertificateAlias = this.mCurrentProfile.getUserCertificateAlias();
startConnection(this.mCurrentProfile);
this.mIsDisconnecting = false;
SimpleFetcher.enable();
addNotification();
this.mBuilderAdapter.setProfile(this.mCurrentProfile);
if (initializeCharon(this.mBuilderAdapter, this.mLogFile, this.mAppDir, this.mCurrentProfile.getVpnType().has(VpnType.a.BYOD))) {
g0.Y("charon started", new Object[0]);
if (this.mCurrentProfile.getVpnType().has(VpnType.a.USER_PASS) && this.mCurrentProfile.getPassword() == null) {
setError(VpnStateService.b.PASSWORD_MISSING);
} else {
com.free.vpn.strongswan.utils.d dVar = new com.free.vpn.strongswan.utils.d();
dVar.c("global.language", Locale.getDefault().getLanguage());
Boolean bool = Boolean.FALSE;
dVar.b("global.crl", bool);
dVar.b("global.ocsp", bool);
dVar.c("connection.type", this.mCurrentProfile.getVpnType().getIdentifier());
dVar.c("connection.server", this.mCurrentProfile.getGateway());
Integer port = this.mCurrentProfile.getPort();
if (port != null) {
str = port.toString();
}
dVar.c("connection.port", str);
dVar.c("connection.username", this.mCurrentProfile.getUsername());
dVar.c("connection.password", this.mCurrentProfile.getPassword());
dVar.c("connection.local_id", this.mCurrentProfile.getLocalId());
dVar.c("connection.remote_id", this.mCurrentProfile.getRemoteId());
dVar.b("connection.certreq", bool);
StringBuilder sb2 = new StringBuilder();
com.free.vpn.strongswan.utils.d.a(dVar.f7062a, sb2);
initiate(sb2.toString());
}
} else {
g0.H("failed to start charon", new Object[0]);
setError(VpnStateService.b.GENERIC_ERROR);
setState(VpnStateService.f.DISABLED);
this.mCurrentProfile = null;
}
}
}
}
}
@Override
public void stateChanged() {
if (this.mShowNotification) {
((NotificationManager) getSystemService("notification")).notify(199, buildNotification(false));
}
updateNetworkSpeed();
}
public void updateImcState(int i10) {
}
public void updateStatus(int i10) {
switch (i10) {
case 1:
setState(VpnStateService.f.CONNECTED);
return;
case 2:
if (this.mIsDisconnecting) {
return;
}
setState(VpnStateService.f.CONNECTING);
return;
case 3:
setErrorDisconnect(VpnStateService.b.AUTH_FAILED);
return;
case 4:
setErrorDisconnect(VpnStateService.b.PEER_AUTH_FAILED);
return;
case 5:
setErrorDisconnect(VpnStateService.b.LOOKUP_FAILED);
return;
case 6:
setErrorDisconnect(VpnStateService.b.UNREACHABLE);
return;
case 7:
setErrorDisconnect(VpnStateService.b.CERTIFICATE_UNAVAILABLE);
return;
case 8:
setErrorDisconnect(VpnStateService.b.GENERIC_ERROR);
return;
default:
g0.H("Unknown status code received", new Object[0]);
return;
}
}
}