TopTV v3.0.1版本的 MD5 值为:0fc1b9ce94885bc92edd11a6ee3e5932
以下内容为反编译后的 OpenVPNService.java 源代码,内容仅作参考
package de.blinkt.openvpn.core;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.UiModeManager;
import android.content.ComponentName;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ShortcutManager;
import android.content.res.Resources;
import android.net.ProxyInfo;
import android.net.VpnService;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.ParcelFileDescriptor;
import android.system.OsConstants;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.widget.Toast;
import com.amazonaws.mobileconnectors.s3.transferutility.TransferService;
import com.toptvone.toptviptvbox.R;
import d.a.a.d.e;
import d.a.a.d.f;
import d.a.a.d.g;
import d.a.a.d.i;
import d.a.a.d.n;
import d.a.a.d.o;
import d.a.a.d.p;
import d.a.a.d.q;
import d.a.a.d.r;
import d.a.a.d.v;
import d.a.a.d.y;
import d.a.a.d.z;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.Iterator;
import java.util.Locale;
import java.util.Vector;
import me.zhanghai.android.materialprogressbar.BuildConfig;
public class OpenVPNService extends VpnService implements z.e, Handler.Callback, z.b, i {
public static boolean f29739b = false;
public String f29744g;
public d.a.a.a f29746i;
public int f29749l;
public g f29751n;
public long q;
public p r;
public String t;
public String u;
public Handler v;
public Toast w;
public Runnable x;
public ProxyInfo y;
public final Vector<String> f29740c = new Vector<>();
public final n f29741d = new n();
public final n f29742e = new n();
public final Object f29743f = new Object();
public Thread f29745h = null;
public String f29747j = null;
public d.a.a.d.b f29748k = null;
public String f29750m = null;
public boolean f29752o = false;
public boolean p = false;
public final IBinder s = new a();
public class a extends i.a {
public a() {
}
@Override
public void I1(String str) {
OpenVPNService.this.I1(str);
}
@Override
public void T1(String str) {
OpenVPNService.this.T1(str);
}
@Override
public boolean e(boolean z) {
return OpenVPNService.this.e(z);
}
@Override
public void f2(boolean z) {
OpenVPNService.this.f2(z);
}
@Override
public boolean g0(String str) {
return OpenVPNService.this.g0(str);
}
@Override
public boolean protect(int i2) {
return OpenVPNService.this.protect(i2);
}
}
public class b implements Runnable {
public final String f29754b;
public b(String str) {
this.f29754b = str;
}
@Override
public void run() {
if (OpenVPNService.this.w != null) {
OpenVPNService.this.w.cancel();
}
String format = String.format(Locale.getDefault(), "%s - %s", OpenVPNService.this.f29746i.f29501f, this.f29754b);
OpenVPNService openVPNService = OpenVPNService.this;
openVPNService.w = Toast.makeText(openVPNService.getBaseContext(), format, 0);
OpenVPNService.this.w.show();
}
}
public class c implements Runnable {
public c() {
}
@Override
public void run() {
OpenVPNService.this.r3();
}
}
public class d implements Runnable {
public d() {
}
@Override
public void run() {
if (OpenVPNService.this.f29751n != null) {
OpenVPNService.this.u3();
}
OpenVPNService openVPNService = OpenVPNService.this;
openVPNService.h3(openVPNService.r);
}
}
public static class e {
public static final int[] f29758a = new int[f.values().length];
}
@SuppressLint({"StringFormatInvalid"})
public static String Z2(long j2, boolean z, Resources resources) {
if (z) {
j2 *= 8;
}
double d2 = j2;
double d3 = z ? 1000 : 1024;
int max = Math.max(0, Math.min((int) (Math.log(d2) / Math.log(d3)), 3));
double pow = Math.pow(d3, max);
Double.isNaN(d2);
float f2 = (float) (d2 / pow);
return z ? max != 0 ? max != 1 ? max != 2 ? resources.getString(R.string.gbits_per_second, Float.valueOf(f2)) : resources.getString(R.string.mbits_per_second, Float.valueOf(f2)) : resources.getString(R.string.kbits_per_second, Float.valueOf(f2)) : resources.getString(R.string.bits_per_second, Float.valueOf(f2)) : max != 0 ? max != 1 ? max != 2 ? resources.getString(R.string.volume_gbyte, Float.valueOf(f2)) : resources.getString(R.string.volume_mbyte, Float.valueOf(f2)) : resources.getString(R.string.volume_kbyte, Float.valueOf(f2)) : resources.getString(R.string.volume_byte, Float.valueOf(f2));
}
@Override
public void A2(String str) {
}
@Override
public void I(String str, String str2, int i2, f fVar, Intent intent) {
String str3;
R2(str, fVar);
if (this.f29745h != null || f29739b) {
if (fVar == f.LEVEL_CONNECTED) {
this.f29752o = true;
this.q = System.currentTimeMillis();
if (!j3()) {
str3 = "openvpn_bg";
q3(z.f(this), z.f(this), str3, 0L, fVar, intent);
}
} else {
this.f29752o = false;
}
str3 = "openvpn_newstat";
q3(z.f(this), z.f(this), str3, 0L, fVar, intent);
}
}
@Override
public void I1(String str) {
new d.a.a.c.b(this).a(str);
}
public void I2(String str) {
this.f29740c.add(str);
}
public boolean J2(String str, int i2) {
if (Build.VERSION.SDK_INT < 21) {
return false;
}
try {
this.y = ProxyInfo.buildDirectProxy(str, i2);
return true;
} catch (Exception e2) {
z.p("Could not set proxy" + e2.getLocalizedMessage());
return false;
}
}
public final void K2() {
Iterator<String> it = o.a(this, false).iterator();
while (it.hasNext()) {
String[] split = it.next().split("/");
String str = split[0];
int parseInt = Integer.parseInt(split[1]);
if (!str.equals(this.f29748k.f29525a)) {
int i2 = Build.VERSION.SDK_INT;
if (i2 < 19 && !this.f29746i.X) {
this.f29741d.b(new d.a.a.d.b(str, parseInt), true);
} else if (i2 >= 19 && this.f29746i.X) {
this.f29741d.a(new d.a.a.d.b(str, parseInt), false);
}
}
}
if (this.f29746i.X) {
Iterator<String> it2 = o.a(this, true).iterator();
while (it2.hasNext()) {
O2(it2.next(), false);
}
}
}
public void L2(d.a.a.d.b bVar, boolean z) {
this.f29741d.a(bVar, z);
}
public void M2(String str, String str2, String str3, String str4) {
d.a.a.d.b bVar = new d.a.a.d.b(str, str2);
boolean b3 = b3(str4);
n.a aVar = new n.a(new d.a.a.d.b(str3, 32), false);
d.a.a.d.b bVar2 = this.f29748k;
if (bVar2 == null) {
z.p("Local IP address unset and received. Neither pushed server config nor local config specifies an IP addresses. Opening tun device is most likely going to fail.");
return;
}
if (new n.a(bVar2, true).c(aVar)) {
b3 = true;
}
if (str3 != null && (str3.equals("255.255.255.255") || str3.equals(this.u))) {
b3 = true;
}
if (bVar.f29526b == 32 && !str2.equals("255.255.255.255")) {
z.y(R.string.route_not_cidr, str, str2);
}
if (bVar.d()) {
z.y(R.string.route_not_netip, str, Integer.valueOf(bVar.f29526b), bVar.f29525a);
}
this.f29741d.a(bVar, b3);
}
public void N2(String str, String str2) {
O2(str, b3(str2));
}
public void O2(String str, boolean z) {
String[] split = str.split("/");
try {
int parseInt = Integer.parseInt(split[1]);
this.f29742e.c((Inet6Address) InetAddress.getAllByName(split[0])[0], parseInt, z);
} catch (UnknownHostException e2) {
z.r(e2);
}
}
public final void P2(Notification.Builder builder) {
PendingIntent service;
int i2;
int i3;
Intent intent = new Intent(this, d.a.a.b.a.class);
intent.setAction("de.blinkt.openvpn.DISCONNECT_VPN");
builder.addAction(R.drawable.ic_cancel, getString(R.string.cancel_connection), PendingIntent.getActivity(this, 0, intent, 67108864));
Intent intent2 = new Intent(this, OpenVPNService.class);
g gVar = this.f29751n;
if (gVar == null || !gVar.h()) {
intent2.setAction("de.blinkt.openvpn.PAUSE_VPN");
service = PendingIntent.getService(this, 0, intent2, 67108864);
i2 = R.drawable.lb_ic_pause;
i3 = R.string.pauseVPN;
} else {
intent2.setAction("de.blinkt.openvpn.RESUME_VPN");
service = PendingIntent.getService(this, 0, intent2, 67108864);
i2 = R.drawable.lb_ic_play;
i3 = R.string.resumevpn;
}
builder.addAction(i2, getString(i3), service);
}
@TargetApi(21)
public final void Q2(VpnService.Builder builder) {
builder.allowFamily(OsConstants.AF_INET);
builder.allowFamily(OsConstants.AF_INET6);
}
public final void R2(String str, f fVar) {
Intent intent = new Intent();
intent.setAction("de.blinkt.openvpn.VPN_STATUS");
intent.putExtra("status", fVar.toString());
intent.putExtra("detailstatus", str);
sendBroadcast(intent, "android.permission.ACCESS_NETWORK_STATE");
}
public final void S2() {
synchronized (this.f29743f) {
this.f29745h = null;
}
z.C(this);
u3();
v.s(this);
this.x = null;
if (this.p) {
return;
}
stopForeground(!f29739b);
if (f29739b) {
return;
}
stopSelf();
z.E(this);
}
@Override
public void T1(String str) {
if (this.r != null) {
this.r.d(Base64.encodeToString(str.getBytes(Charset.forName("UTF-8")), 0));
}
}
public void T2() {
synchronized (this.f29743f) {
Thread thread = this.f29745h;
if (thread != null) {
thread.interrupt();
try {
Thread.sleep(1000L);
} catch (InterruptedException unused) {
}
}
}
}
public PendingIntent U2() {
Intent intent = new Intent();
intent.setComponent(new ComponentName(this, getPackageName() + ".activities.MainActivity"));
intent.putExtra("PAGE", "graph");
intent.addFlags(131072);
PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 67108864);
intent.addFlags(131072);
return activity;
}
public final int V2(f fVar) {
int i2 = e.f29758a[fVar.ordinal()];
return R.mipmap.ic_launcher;
}
public p W2() {
return this.r;
}
public final String X2() {
String str = "TUNCFG UNQIUE STRING ips:";
if (this.f29748k != null) {
str = "TUNCFG UNQIUE STRING ips:" + this.f29748k.toString();
}
if (this.f29750m != null) {
str = str + this.f29750m;
}
return (((((str + "routes: " + TextUtils.join("|", this.f29741d.f(true)) + TextUtils.join("|", this.f29742e.f(true))) + "excl. routes:" + TextUtils.join("|", this.f29741d.f(false)) + TextUtils.join("|", this.f29742e.f(false))) + "dns: " + TextUtils.join("|", this.f29740c)) + "domain: " + this.f29747j) + "mtu: " + this.f29749l) + "proxyInfo: " + this.y;
}
@Override
public void Y0(long j2, long j3, long j4, long j5) {
if (this.f29752o) {
q3(String.format(getString(R.string.statusline_bytecount), Z2(j2, false, getResources()), Z2(j4 / 2, true, getResources()), Z2(j3, false, getResources()), Z2(j5 / 2, true, getResources())), null, "openvpn_bg", this.q, f.LEVEL_CONNECTED, null);
}
}
public String Y2() {
if (X2().equals(this.t)) {
return "NOACTION";
}
String str = Build.VERSION.RELEASE;
return (Build.VERSION.SDK_INT != 19 || str.startsWith("4.4.3") || str.startsWith("4.4.4") || str.startsWith("4.4.5") || str.startsWith("4.4.6")) ? "OPEN_BEFORE_CLOSE" : "OPEN_AFTER_CLOSE";
}
public final p a3() {
try {
return (p) Class.forName("de.blinkt.openvpn.core.OpenVPNThreadv3").getConstructor(OpenVPNService.class, d.a.a.a.class).newInstance(this, this.f29746i);
} catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException | InstantiationException | NoSuchMethodException | InvocationTargetException e2) {
e2.printStackTrace();
return null;
}
}
@Override
public IBinder asBinder() {
return this.s;
}
public final boolean b3(String str) {
return str != null && (str.startsWith("tun") || "(null)".equals(str) || "vpnservice-tun".equals(str));
}
public final boolean c3() {
if (Build.VERSION.SDK_INT >= 29) {
return isLockdownEnabled();
}
return false;
}
@TargetApi(16)
public final void d3(int i2, Notification.Builder builder) {
if (i2 != 0) {
try {
builder.getClass().getMethod("setPriority", Integer.TYPE).invoke(builder, Integer.valueOf(i2));
builder.getClass().getMethod("setUsesChronometer", Boolean.TYPE).invoke(builder, Boolean.TRUE);
} catch (IllegalAccessException | IllegalArgumentException | NoSuchMethodException | InvocationTargetException e2) {
z.r(e2);
}
}
}
@Override
public boolean e(boolean z) {
if (W2() != null) {
return W2().e(z);
}
return false;
}
@TargetApi(21)
public final void e3(Notification.Builder builder, String str) {
builder.setCategory(str);
builder.setLocalOnly(true);
}
@Override
public void f2(boolean z) {
g gVar = this.f29751n;
if (gVar != null) {
gVar.k(z);
}
}
public ParcelFileDescriptor f3() {
int i2;
String str;
int i3;
VpnService.Builder builder = new VpnService.Builder(this);
z.t(R.string.last_openvpn_tun_config, new Object[0]);
boolean z = Build.VERSION.SDK_INT >= 21 && !this.f29746i.A0;
if (z) {
Q2(builder);
}
d.a.a.d.b bVar = this.f29748k;
if (bVar == null && this.f29750m == null) {
z.p(getString(R.string.opentun_no_ipaddr));
return null;
}
if (bVar != null) {
if (!d.a.a.a.h(this)) {
K2();
}
try {
d.a.a.d.b bVar2 = this.f29748k;
builder.addAddress(bVar2.f29525a, bVar2.f29526b);
} catch (IllegalArgumentException e2) {
z.o(R.string.dns_add_error, this.f29748k, e2.getLocalizedMessage());
return null;
}
}
String str2 = this.f29750m;
if (str2 != null) {
String[] split = str2.split("/");
try {
builder.addAddress(split[0], Integer.parseInt(split[1]));
} catch (IllegalArgumentException e3) {
z.o(R.string.ip_add_error, this.f29750m, e3.getLocalizedMessage());
return null;
}
}
Iterator<String> it = this.f29740c.iterator();
while (it.hasNext()) {
String next = it.next();
try {
builder.addDnsServer(next);
} catch (IllegalArgumentException e4) {
z.o(R.string.dns_add_error, next, e4.getLocalizedMessage());
}
}
String str3 = Build.VERSION.RELEASE;
int i4 = Build.VERSION.SDK_INT;
if (i4 != 19 || str3.startsWith("4.4.3") || str3.startsWith("4.4.4") || str3.startsWith("4.4.5") || str3.startsWith("4.4.6") || (i3 = this.f29749l) >= 1280) {
builder.setMtu(this.f29749l);
} else {
z.u(String.format(Locale.US, "Forcing MTU to 1280 instead of %d to workaround Android Bug #70916", Integer.valueOf(i3)));
builder.setMtu(1280);
}
Collection<n.a> g2 = this.f29741d.g();
Collection<n.a> g3 = this.f29742e.g();
if ("samsung".equals(Build.BRAND) && i4 >= 21 && this.f29740c.size() >= 1) {
try {
n.a aVar = new n.a(new d.a.a.d.b(this.f29740c.get(0), 32), true);
boolean z2 = false;
for (n.a aVar2 : g2) {
if (aVar2.c(aVar)) {
z2 = true;
}
}
if (!z2) {
z.z(String.format("Warning Samsung Android 5.0+ devices ignore DNS servers outside the VPN range. To enable DNS resolution a route to your DNS Server (%s) has been added.", this.f29740c.get(0)));
g2.add(aVar);
}
} catch (Exception unused) {
if (!this.f29740c.get(0).contains(":")) {
z.p("Error parsing DNS Server IP: " + this.f29740c.get(0));
}
}
}
n.a aVar3 = new n.a(new d.a.a.d.b("224.0.0.0", 3), true);
for (n.a aVar4 : g2) {
try {
if (aVar3.c(aVar4)) {
z.l(R.string.ignore_multicast_route, aVar4.toString());
} else {
builder.addRoute(aVar4.g(), aVar4.f29584c);
}
} catch (IllegalArgumentException e5) {
z.p(getString(R.string.route_rejected) + aVar4 + " " + e5.getLocalizedMessage());
}
}
for (n.a aVar5 : g3) {
try {
builder.addRoute(aVar5.i(), aVar5.f29584c);
} catch (IllegalArgumentException e6) {
z.p(getString(R.string.route_rejected) + aVar5 + " " + e6.getLocalizedMessage());
}
}
String str4 = this.f29747j;
if (str4 != null) {
builder.addSearchDomain(str4);
}
String str5 = "(not set, allowed)";
String str6 = "(not set)";
if (z) {
str6 = "(not set, allowed)";
} else {
str5 = "(not set)";
}
d.a.a.d.b bVar3 = this.f29748k;
if (bVar3 != null) {
int i5 = bVar3.f29526b;
String str7 = bVar3.f29525a;
i2 = i5;
str5 = str7;
} else {
i2 = -1;
}
String str8 = this.f29750m;
if (str8 != null) {
str6 = str8;
}
if ((!this.f29741d.f(false).isEmpty() || !this.f29742e.f(false).isEmpty()) && c3()) {
z.u("VPN lockdown enabled (do not allow apps to bypass VPN) enabled. Route exclusion will not allow apps to bypass VPN (e.g. bypass VPN for local networks)");
}
z.t(R.string.local_ip_info, str5, Integer.valueOf(i2), str6, Integer.valueOf(this.f29749l));
z.t(R.string.dns_server_info, TextUtils.join(", ", this.f29740c), this.f29747j);
z.t(R.string.routes_info_incl, TextUtils.join(", ", this.f29741d.f(true)), TextUtils.join(", ", this.f29742e.f(true)));
z.t(R.string.routes_info_excl, TextUtils.join(", ", this.f29741d.f(false)), TextUtils.join(", ", this.f29742e.f(false)));
ProxyInfo proxyInfo = this.y;
if (proxyInfo != null && Build.VERSION.SDK_INT >= 21) {
z.t(R.string.proxy_info, proxyInfo.getHost(), Integer.valueOf(this.y.getPort()));
}
z.l(R.string.routes_debug, TextUtils.join(", ", g2), TextUtils.join(", ", g3));
int i6 = Build.VERSION.SDK_INT;
if (i6 >= 21) {
k3(builder);
}
if (i6 >= 22) {
builder.setUnderlyingNetworks(null);
}
if (i6 >= 29) {
builder.setMetered(false);
}
String str9 = this.f29746i.f29501f;
d.a.a.d.b bVar4 = this.f29748k;
builder.setSession((bVar4 == null || (str = this.f29750m) == null) ? bVar4 != null ? getString(R.string.session_ipv4string, new Object[]{str9, bVar4}) : getString(R.string.session_ipv4string, new Object[]{str9, this.f29750m}) : getString(R.string.session_ipv6string, new Object[]{str9, bVar4, str}));
if (this.f29740c.size() == 0) {
z.t(R.string.warn_no_dns, new Object[0]);
}
m3(builder);
this.t = X2();
this.f29740c.clear();
this.f29741d.d();
this.f29742e.d();
this.f29748k = null;
this.f29750m = null;
this.f29747j = null;
this.y = null;
builder.setConfigureIntent(U2());
try {
ParcelFileDescriptor establish = builder.establish();
if (establish != null) {
return establish;
}
throw new NullPointerException("Android establish() method returned null (Really broken network configuration?)");
} catch (Exception e7) {
z.n(R.string.tun_open_error);
z.p(getString(R.string.error) + e7.getLocalizedMessage());
if (Build.VERSION.SDK_INT <= 17) {
z.n(R.string.tun_error_helpful);
return null;
}
return null;
}
}
@Override
public boolean g0(String str) {
return new d.a.a.c.b(this).c(this, str);
}
public void g3() {
S2();
}
public synchronized void h3(p pVar) {
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
intentFilter.addAction("android.intent.action.SCREEN_OFF");
intentFilter.addAction("android.intent.action.SCREEN_ON");
g gVar = new g(pVar);
this.f29751n = gVar;
gVar.i(this);
registerReceiver(this.f29751n, intentFilter);
z.a(this.f29751n);
}
@Override
public boolean handleMessage(Message message) {
Runnable callback = message.getCallback();
if (callback != null) {
callback.run();
return true;
}
return false;
}
public void i3(int i2, String str) {
f fVar = f.LEVEL_WAITING_FOR_USER_INPUT;
z.J("NEED", "need " + str, i2, fVar);
q3(getString(i2), getString(i2), "openvpn_newstat", 0L, fVar, null);
}
public final boolean j3() {
return ((UiModeManager) getSystemService("uimode")).getCurrentModeType() == 4;
}
@TargetApi(21)
public final void k3(VpnService.Builder builder) {
boolean z = false;
for (d.a.a.d.e eVar : this.f29746i.f0) {
if (eVar.f29543i == e.a.ORBOT) {
z = true;
}
}
if (z) {
z.m("VPN Profile uses at least one server entry with Orbot. Setting up VPN so that OrBot is not redirected over VPN.");
}
if (this.f29746i.i0 && z) {
try {
builder.addDisallowedApplication("org.torproject.android");
} catch (PackageManager.NameNotFoundException unused) {
z.m("Orbot not installed?");
}
}
try {
builder.addAllowedApplication(getPackageName());
} catch (PackageManager.NameNotFoundException e2) {
z.p("This should not happen: " + e2.getLocalizedMessage());
}
d.a.a.a aVar = this.f29746i;
if (aVar.i0) {
z.l(R.string.disallowed_vpn_apps_info, TextUtils.join(", ", aVar.h0));
} else {
z.l(R.string.allowed_vpn_apps_info, TextUtils.join(", ", aVar.h0));
}
if (this.f29746i.j0) {
builder.allowBypass();
z.m("Apps may bypass VPN");
}
}
public void l3(String str) {
if (this.f29747j == null) {
this.f29747j = str;
}
}
public final void m3(VpnService.Builder builder) {
ProxyInfo proxyInfo = this.y;
if (proxyInfo != null && Build.VERSION.SDK_INT >= 29) {
builder.setHttpProxy(proxyInfo);
} else if (proxyInfo != null) {
z.z("HTTP Proxy needs Android 10 or later.");
}
}
public void n3(String str, String str2, int i2, String str3) {
long j2;
int i3;
this.f29748k = new d.a.a.d.b(str, str2);
this.f29749l = i2;
this.u = null;
long c2 = d.a.a.d.b.c(str2);
if (this.f29748k.f29526b == 32 && !str2.equals("255.255.255.255")) {
if ("net30".equals(str3)) {
j2 = -4;
i3 = 30;
} else {
j2 = -2;
i3 = 31;
}
int i4 = ((c2 & j2) > (this.f29748k.b() & j2) ? 1 : ((c2 & j2) == (this.f29748k.b() & j2) ? 0 : -1));
d.a.a.d.b bVar = this.f29748k;
if (i4 == 0) {
bVar.f29526b = i3;
} else {
bVar.f29526b = 32;
if (!"p2p".equals(str3)) {
z.y(R.string.ip_not_cidr, str, str2, str3);
}
}
}
if (("p2p".equals(str3) && this.f29748k.f29526b < 32) || ("net30".equals(str3) && this.f29748k.f29526b < 30)) {
z.y(R.string.ip_looks_like_subnet, str, str2, str3);
}
d.a.a.d.b bVar2 = this.f29748k;
int i5 = bVar2.f29526b;
if (i5 <= 31 && Build.VERSION.SDK_INT >= 21) {
d.a.a.d.b bVar3 = new d.a.a.d.b(bVar2.f29525a, i5);
bVar3.d();
L2(bVar3, true);
}
this.u = str2;
}
public void o3(String str) {
this.f29750m = str;
}
@Override
public IBinder onBind(Intent intent) {
String action = intent.getAction();
return (action == null || !action.equals("de.blinkt.openvpn.START_SERVICE")) ? super.onBind(intent) : this.s;
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onDestroy() {
synchronized (this.f29743f) {
if (this.f29745h != null) {
this.r.e(true);
}
}
g gVar = this.f29751n;
if (gVar != null) {
unregisterReceiver(gVar);
}
z.E(this);
z.e();
}
@Override
public void onRevoke() {
z.n(R.string.permission_revoked);
this.r.e(false);
S2();
}
@Override
public int onStartCommand(Intent intent, int i2, int i3) {
if (intent != null && intent.getBooleanExtra("de.blinkt.openvpn.NOTIFICATION_ALWAYS_VISIBLE", false)) {
f29739b = true;
}
z.c(this);
z.a(this);
this.v = new Handler(getMainLooper());
if (intent != null && "de.blinkt.openvpn.PAUSE_VPN".equals(intent.getAction())) {
g gVar = this.f29751n;
if (gVar != null) {
gVar.k(true);
}
return 2;
} else if (intent != null && "de.blinkt.openvpn.RESUME_VPN".equals(intent.getAction())) {
g gVar2 = this.f29751n;
if (gVar2 != null) {
gVar2.k(false);
}
return 2;
} else if (intent != null && "de.blinkt.openvpn.START_SERVICE".equals(intent.getAction())) {
return 2;
} else {
if (intent != null && "de.blinkt.openvpn.START_SERVICE_STICKY".equals(intent.getAction())) {
return 3;
}
z.t(R.string.building_configration, new Object[0]);
f fVar = f.LEVEL_START;
z.J("VPN_GENERATE_CONFIG", BuildConfig.FLAVOR, R.string.building_configration, fVar);
q3(z.f(this), z.f(this), "openvpn_newstat", 0L, fVar, null);
if (intent != null) {
if (intent.hasExtra(getPackageName() + ".profileUUID")) {
String stringExtra = intent.getStringExtra(getPackageName() + ".profileUUID");
d.a.a.a d2 = v.d(this, stringExtra, intent.getIntExtra(getPackageName() + ".profileVersion", 0), 100);
this.f29746i = d2;
if (Build.VERSION.SDK_INT >= 25) {
v3(d2);
}
if (this.f29746i != null) {
stopSelf(i3);
return 2;
}
new Thread(new c()).start();
v.r(this, this.f29746i);
z.F(this.f29746i.F());
return 1;
}
}
this.f29746i = v.h(this);
z.t(R.string.service_restarted, new Object[0]);
if (this.f29746i == null) {
Log.d("OpenVPN", "Got no last connected profile on null intent. Assuming always on.");
d.a.a.a f2 = v.f(this);
this.f29746i = f2;
if (f2 == null) {
stopSelf(i3);
return 2;
}
}
this.f29746i.a(this);
if (this.f29746i != null) {
}
}
}
public void p3(int i2) {
this.f29749l = i2;
}
public final void q3(String str, String str2, String str3, long j2, f fVar, Intent intent) {
NotificationManager notificationManager = (NotificationManager) getSystemService(TransferService.INTENT_KEY_NOTIFICATION);
int V2 = V2(fVar);
Notification.Builder builder = new Notification.Builder(this);
int i2 = str3.equals("openvpn_bg") ? -2 : str3.equals("openvpn_userreq") ? 2 : 0;
d.a.a.a aVar = this.f29746i;
builder.setContentTitle(aVar != null ? getString(R.string.notifcation_title, new Object[]{aVar.f29501f}) : getString(R.string.notifcation_title_notconnect));
builder.setContentText(str);
builder.setOnlyAlertOnce(true);
builder.setOngoing(true);
builder.setSmallIcon(V2);
builder.setContentIntent(fVar == f.LEVEL_WAITING_FOR_USER_INPUT ? PendingIntent.getActivity(this, 0, intent, 0) : U2());
if (j2 != 0) {
builder.setWhen(j2);
}
int i3 = Build.VERSION.SDK_INT;
if (i3 >= 16) {
d3(i2, builder);
P2(builder);
}
if (i3 >= 21) {
e3(builder, "service");
}
if (i3 >= 26) {
notificationManager.createNotificationChannel(new NotificationChannel(str3, str3, 3));
builder.setChannelId(str3);
d.a.a.a aVar2 = this.f29746i;
if (aVar2 != null) {
builder.setShortcutId(aVar2.F());
}
}
if (str2 != null && !str2.equals(BuildConfig.FLAVOR)) {
builder.setTicker(str2);
}
Notification notification = builder.getNotification();
int hashCode = str3.hashCode();
notificationManager.notify(hashCode, notification);
startForeground(hashCode, notification);
String str4 = this.f29744g;
if (str4 != null && !str3.equals(str4)) {
notificationManager.cancel(this.f29744g.hashCode());
}
if (!j3() || i2 < 0) {
return;
}
this.v.post(new b(str));
}
public final void r3() {
String str;
Runnable runnable;
try {
this.f29746i.T(this);
String str2 = getApplicationInfo().nativeLibraryDir;
try {
str = getApplication().getCacheDir().getCanonicalPath();
} catch (IOException e2) {
e2.printStackTrace();
str = "/tmp";
}
String[] a2 = y.a(this);
this.p = true;
s3();
this.p = false;
boolean h2 = d.a.a.a.h(this);
if (!h2) {
r rVar = new r(this.f29746i, this);
if (!rVar.p(this)) {
S2();
return;
}
new Thread(rVar, "OpenVPNManagementThread").start();
this.r = rVar;
z.u("started Socket Thread");
}
if (h2) {
p a3 = a3();
runnable = (Runnable) a3;
this.r = a3;
} else {
q qVar = new q(this, a2, str2, str);
this.x = qVar;
runnable = qVar;
}
synchronized (this.f29743f) {
Thread thread = new Thread(runnable, "OpenVPNProcessThread");
this.f29745h = thread;
thread.start();
}
new Handler(getMainLooper()).post(new d());
} catch (IOException e3) {
z.s("Error writing config file", e3);
S2();
}
}
public final void s3() {
if (this.r != null) {
Runnable runnable = this.x;
if (runnable != null) {
((q) runnable).b();
}
if (this.r.e(true)) {
try {
Thread.sleep(1000L);
} catch (InterruptedException unused) {
}
}
}
T2();
}
public void t3(String str) {
String str2 = str.split(":", 2)[0];
NotificationManager notificationManager = (NotificationManager) getSystemService(TransferService.INTENT_KEY_NOTIFICATION);
Notification.Builder builder = new Notification.Builder(this);
builder.setAutoCancel(true);
builder.setSmallIcon(17301659);
str2.hashCode();
if (!str2.equals("CR_TEXT")) {
z.p("Unknown SSO method found: " + str2);
return;
}
String str3 = str.split(":", 2)[1];
builder.setContentTitle(getString(R.string.crtext_requested));
builder.setContentText(str3);
Intent intent = new Intent();
intent.setComponent(new ComponentName(this, getPackageName() + ".activities.CredentialsPopup"));
intent.putExtra("de.blinkt.openvpn.core.CR_TEXT_CHALLENGE", str3);
PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 67108864);
z.K("USER_INPUT", "waiting for user input", R.string.crtext_requested, f.LEVEL_WAITING_FOR_USER_INPUT, intent);
builder.setContentIntent(activity);
int i2 = Build.VERSION.SDK_INT;
if (i2 >= 16) {
d3(2, builder);
}
if (i2 >= 21) {
e3(builder, "status");
}
if (i2 >= 26) {
builder.setChannelId("openvpn_userreq");
}
notificationManager.notify(-370124770, builder.getNotification());
}
public synchronized void u3() {
g gVar = this.f29751n;
if (gVar != null) {
try {
z.C(gVar);
unregisterReceiver(this.f29751n);
} catch (IllegalArgumentException e2) {
e2.printStackTrace();
}
}
this.f29751n = null;
}
public final void v3(d.a.a.a aVar) {
if (aVar == null) {
return;
}
((ShortcutManager) getSystemService(ShortcutManager.class)).reportShortcutUsed(aVar.F());
}
}