CCIPTV PRO v3.0.9.1版本的 MD5 值为:e78d4d980447be4a9f823314f45bbf03

以下内容为反编译后的 OpenVPNService.java 源代码,内容仅作参考


package de.blinkt.openvpn.core;

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.Uri;
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 boxbr.apksrebrand.smarters.vpn.DisconnectVPN;
import com.iptvsmarters.cciptv.R;
import g.a.a.c.d;
import g.a.a.c.f;
import g.a.a.c.h;
import g.a.a.c.m;
import g.a.a.c.n;
import g.a.a.c.o;
import g.a.a.c.p;
import g.a.a.c.q;
import g.a.a.c.u;
import g.a.a.c.x;
import g.a.a.c.y;
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 org.joda.time.chrono.BasicChronology;
import org.jsoup.helper.DataUtil;
public class OpenVPNService extends VpnService implements y.e, Handler.Callback, y.b, h {
    public static boolean x = false;
    public String f4523f;
    public g.a.a.a f4525h;
    public int f4528k;
    public f f4530m;
    public long f4533p;
    public o f4534q;
    public String s;
    public String t;
    public Handler u;
    public Toast v;
    public Runnable w;
    public final Vector<String> b = new Vector<>();
    public final m c = new m();
    public final m f4521d = new m();
    public final Object f4522e = new Object();
    public Thread f4524g = null;
    public String f4526i = null;
    public g.a.a.c.b f4527j = null;
    public String f4529l = null;
    public boolean f4531n = false;
    public boolean f4532o = false;
    public final IBinder r = new a();

    public class a extends h.a {
        public a() {
        }

        @Override
        public void Q1(String str) {
            OpenVPNService.this.Q1(str);
        }

        @Override
        public void a2(String str) {
            OpenVPNService.this.a2(str);
        }

        @Override
        public boolean k(boolean z) {
            return OpenVPNService.this.k(z);
        }

        @Override
        public void l2(boolean z) {
            OpenVPNService.this.l2(z);
        }

        @Override
        public boolean protect(int i2) {
            return OpenVPNService.this.protect(i2);
        }

        @Override
        public boolean q0(String str) {
            return OpenVPNService.this.q0(str);
        }
    }

    public class b implements Runnable {
        public final String b;

        public b(String str) {
            this.b = str;
        }

        @Override
        public void run() {
            if (OpenVPNService.this.v != null) {
                OpenVPNService.this.v.cancel();
            }
            String format = String.format(Locale.getDefault(), "%s - %s", OpenVPNService.this.f4525h.f10574d, this.b);
            OpenVPNService openVPNService = OpenVPNService.this;
            openVPNService.v = Toast.makeText(openVPNService.getBaseContext(), format, 0);
            OpenVPNService.this.v.show();
        }
    }

    public class c implements Runnable {
        public c() {
        }

        @Override
        public void run() {
            OpenVPNService.this.t3();
        }
    }

    public class d implements Runnable {
        public d() {
        }

        @Override
        public void run() {
            if (OpenVPNService.this.f4530m != null) {
                OpenVPNService.this.w3();
            }
            OpenVPNService openVPNService = OpenVPNService.this;
            openVPNService.k3(openVPNService.f4534q);
        }
    }

    public static class e {
        public static final int[] a = new int[g.a.a.c.e.values().length];
    }

    public static String c3(long j2, boolean z, Resources resources) {
        if (z) {
            j2 *= 8;
        }
        double d2 = j2;
        double d3 = z ? 1000 : BasicChronology.CACHE_SIZE;
        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 E2(String str) {
    }

    public void M2(String str) {
        this.b.add(str);
    }

    public final void N2() {
        Iterator<String> it = n.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.f4527j.a)) {
                if (Build.VERSION.SDK_INT < 19 && !this.f4525h.U) {
                    this.c.b(new g.a.a.c.b(str, parseInt), true);
                } else if (Build.VERSION.SDK_INT >= 19 && this.f4525h.U) {
                    this.c.a(new g.a.a.c.b(str, parseInt), false);
                }
            }
        }
        if (this.f4525h.U) {
            Iterator<String> it2 = n.a(this, true).iterator();
            while (it2.hasNext()) {
                R2(it2.next(), false);
            }
        }
    }

    public void O2(g.a.a.c.b bVar, boolean z) {
        this.c.a(bVar, z);
    }

    public void P2(String str, String str2, String str3, String str4) {
        g.a.a.c.b bVar = new g.a.a.c.b(str, str2);
        boolean e3 = e3(str4);
        m.a aVar = new m.a(new g.a.a.c.b(str3, 32), false);
        g.a.a.c.b bVar2 = this.f4527j;
        if (bVar2 == null) {
            y.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 m.a(bVar2, true).g(aVar)) {
            e3 = true;
        }
        if (str3 != null && (str3.equals("255.255.255.255") || str3.equals(this.t))) {
            e3 = true;
        }
        if (bVar.b == 32 && !str2.equals("255.255.255.255")) {
            y.y(R.string.route_not_cidr, str, str2);
        }
        if (bVar.d()) {
            y.y(R.string.route_not_netip, str, Integer.valueOf(bVar.b), bVar.a);
        }
        this.c.a(bVar, e3);
    }

    @Override
    public void Q1(String str) {
        new g.a.a.b.b(this).a(str);
    }

    public void Q2(String str, String str2) {
        R2(str, e3(str2));
    }

    public void R2(String str, boolean z) {
        String[] split = str.split("/");
        try {
            int parseInt = Integer.parseInt(split[1]);
            this.f4521d.c((Inet6Address) InetAddress.getAllByName(split[0])[0], parseInt, z);
        } catch (UnknownHostException e2) {
            y.r(e2);
        }
    }

    public final void S2(Notification.Builder builder) {
        PendingIntent service;
        int i2;
        int i3;
        Intent intent = new Intent(this, DisconnectVPN.class);
        intent.setAction("de.blinkt.openvpn.DISCONNECT_VPN");
        builder.addAction(R.drawable.ic_cancel, getString(R.string.cancel_connection), PendingIntent.getActivity(this, 0, intent, 0));
        Intent intent2 = new Intent(this, OpenVPNService.class);
        f fVar = this.f4530m;
        if (fVar == null || !fVar.h()) {
            intent2.setAction("de.blinkt.openvpn.PAUSE_VPN");
            service = PendingIntent.getService(this, 0, intent2, 0);
            i2 = R.drawable.lb_ic_pause;
            i3 = R.string.pauseVPN;
        } else {
            intent2.setAction("de.blinkt.openvpn.RESUME_VPN");
            service = PendingIntent.getService(this, 0, intent2, 0);
            i2 = R.drawable.lb_ic_play;
            i3 = R.string.resumevpn;
        }
        builder.addAction(i2, getString(i3), service);
    }

    @TargetApi(21)
    public final void T2(VpnService.Builder builder) {
        builder.allowFamily(OsConstants.AF_INET);
        builder.allowFamily(OsConstants.AF_INET6);
    }

    public final void U2(String str, g.a.a.c.e eVar) {
        Intent intent = new Intent();
        intent.setAction("de.blinkt.openvpn.VPN_STATUS");
        intent.putExtra("status", eVar.toString());
        intent.putExtra("detailstatus", str);
        sendBroadcast(intent, "android.permission.ACCESS_NETWORK_STATE");
    }

    public final void V2() {
        synchronized (this.f4522e) {
            this.f4524g = null;
        }
        y.C(this);
        w3();
        u.s(this);
        this.w = null;
        if (this.f4532o) {
            return;
        }
        stopForeground(!x);
        if (x) {
            return;
        }
        stopSelf();
        y.E(this);
    }

    public void W2() {
        synchronized (this.f4522e) {
            if (this.f4524g != null) {
                this.f4524g.interrupt();
                try {
                    Thread.sleep(1000L);
                } catch (InterruptedException unused) {
                }
            }
        }
    }

    public PendingIntent X2() {
        Intent intent = new Intent();
        intent.setComponent(new ComponentName(this, getPackageName() + ".activities.MainActivity"));
        intent.putExtra("PAGE", "graph");
        intent.addFlags(DataUtil.bufferSize);
        PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0);
        intent.addFlags(DataUtil.bufferSize);
        return activity;
    }

    public final int Y2(g.a.a.c.e eVar) {
        int i2 = e.a[eVar.ordinal()];
        return R.mipmap.ic_launcher;
    }

    public o Z2() {
        return this.f4534q;
    }

    @Override
    public void a2(String str) {
        if (this.f4534q != null) {
            this.f4534q.d(Base64.encodeToString(str.getBytes(Charset.forName(DataUtil.defaultCharset)), 0));
        }
    }

    public final String a3() {
        String str = "TUNCFG UNQIUE STRING ips:";
        if (this.f4527j != null) {
            str = "TUNCFG UNQIUE STRING ips:" + this.f4527j.toString();
        }
        if (this.f4529l != null) {
            str = str + this.f4529l;
        }
        return ((((str + "routes: " + TextUtils.join("|", this.c.f(true)) + TextUtils.join("|", this.f4521d.f(true))) + "excl. routes:" + TextUtils.join("|", this.c.f(false)) + TextUtils.join("|", this.f4521d.f(false))) + "dns: " + TextUtils.join("|", this.b)) + "domain: " + this.f4526i) + "mtu: " + this.f4528k;
    }

    @Override
    public IBinder asBinder() {
        return this.r;
    }

    public String b3() {
        if (a3().equals(this.s)) {
            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 o d3() {
        try {
            return (o) Class.forName("de.blinkt.openvpn.core.OpenVPNThreadv3").getConstructor(OpenVPNService.class, g.a.a.a.class).newInstance(this, this.f4525h);
        } catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException | InstantiationException | NoSuchMethodException | InvocationTargetException e2) {
            e2.printStackTrace();
            return null;
        }
    }

    public final boolean e3(String str) {
        return str != null && (str.startsWith("tun") || "(null)".equals(str) || "vpnservice-tun".equals(str));
    }

    public final boolean f3() {
        if (Build.VERSION.SDK_INT >= 29) {
            return isLockdownEnabled();
        }
        return false;
    }

    @TargetApi(16)
    public final void g3(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) {
                y.r(e2);
            }
        }
    }

    @TargetApi(21)
    public final void h3(Notification.Builder builder, String str) {
        builder.setCategory(str);
        builder.setLocalOnly(true);
    }

    @Override
    public boolean handleMessage(Message message) {
        Runnable callback = message.getCallback();
        if (callback != null) {
            callback.run();
            return true;
        }
        return false;
    }

    public ParcelFileDescriptor i3() {
        int i2;
        String string;
        String str;
        int i3;
        VpnService.Builder builder = new VpnService.Builder(this);
        y.t(R.string.last_openvpn_tun_config, new Object[0]);
        boolean z = Build.VERSION.SDK_INT >= 21 && !this.f4525h.s0;
        if (z) {
            T2(builder);
        }
        if (this.f4527j == null && this.f4529l == null) {
            y.p(getString(R.string.opentun_no_ipaddr));
            return null;
        }
        if (this.f4527j != null) {
            if (!g.a.a.a.h(this)) {
                N2();
            }
            try {
                builder.addAddress(this.f4527j.a, this.f4527j.b);
            } catch (IllegalArgumentException e2) {
                y.o(R.string.dns_add_error, this.f4527j, e2.getLocalizedMessage());
                return null;
            }
        }
        String str2 = this.f4529l;
        if (str2 != null) {
            String[] split = str2.split("/");
            try {
                builder.addAddress(split[0], Integer.parseInt(split[1]));
            } catch (IllegalArgumentException e3) {
                y.o(R.string.ip_add_error, this.f4529l, e3.getLocalizedMessage());
                return null;
            }
        }
        Iterator<String> it = this.b.iterator();
        while (it.hasNext()) {
            String next = it.next();
            try {
                builder.addDnsServer(next);
            } catch (IllegalArgumentException e4) {
                y.o(R.string.dns_add_error, next, e4.getLocalizedMessage());
            }
        }
        String str3 = Build.VERSION.RELEASE;
        if (Build.VERSION.SDK_INT != 19 || str3.startsWith("4.4.3") || str3.startsWith("4.4.4") || str3.startsWith("4.4.5") || str3.startsWith("4.4.6") || (i3 = this.f4528k) >= 1280) {
            builder.setMtu(this.f4528k);
        } else {
            y.u(String.format(Locale.US, "Forcing MTU to 1280 instead of %d to workaround Android Bug #70916", Integer.valueOf(i3)));
            builder.setMtu(1280);
        }
        Collection<m.a> g2 = this.c.g();
        Collection<m.a> g3 = this.f4521d.g();
        if ("samsung".equals(Build.BRAND) && Build.VERSION.SDK_INT >= 21 && this.b.size() >= 1) {
            try {
                m.a aVar = new m.a(new g.a.a.c.b(this.b.get(0), 32), true);
                boolean z2 = false;
                for (m.a aVar2 : g2) {
                    if (aVar2.g(aVar)) {
                        z2 = true;
                    }
                }
                if (!z2) {
                    y.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.b.get(0)));
                    g2.add(aVar);
                }
            } catch (Exception unused) {
                if (!this.b.get(0).contains(":")) {
                    y.p("Error parsing DNS Server IP: " + this.b.get(0));
                }
            }
        }
        m.a aVar3 = new m.a(new g.a.a.c.b("224.0.0.0", 3), true);
        for (m.a aVar4 : g2) {
            try {
                if (aVar3.g(aVar4)) {
                    y.l(R.string.ignore_multicast_route, aVar4.toString());
                } else {
                    builder.addRoute(aVar4.k(), aVar4.c);
                }
            } catch (IllegalArgumentException e5) {
                y.p(getString(R.string.route_rejected) + aVar4 + " " + e5.getLocalizedMessage());
            }
        }
        for (m.a aVar5 : g3) {
            try {
                builder.addRoute(aVar5.l(), aVar5.c);
            } catch (IllegalArgumentException e6) {
                y.p(getString(R.string.route_rejected) + aVar5 + " " + e6.getLocalizedMessage());
            }
        }
        String str4 = this.f4526i;
        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)";
        }
        g.a.a.c.b bVar = this.f4527j;
        if (bVar != null) {
            int i4 = bVar.b;
            String str7 = bVar.a;
            i2 = i4;
            str5 = str7;
        } else {
            i2 = -1;
        }
        String str8 = this.f4529l;
        if (str8 != null) {
            str6 = str8;
        }
        if ((!this.c.f(false).isEmpty() || !this.f4521d.f(false).isEmpty()) && f3()) {
            y.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)");
        }
        y.t(R.string.local_ip_info, str5, Integer.valueOf(i2), str6, Integer.valueOf(this.f4528k));
        y.t(R.string.dns_server_info, TextUtils.join(", ", this.b), this.f4526i);
        y.t(R.string.routes_info_incl, TextUtils.join(", ", this.c.f(true)), TextUtils.join(", ", this.f4521d.f(true)));
        y.t(R.string.routes_info_excl, TextUtils.join(", ", this.c.f(false)), TextUtils.join(", ", this.f4521d.f(false)));
        y.l(R.string.routes_debug, TextUtils.join(", ", g2), TextUtils.join(", ", g3));
        if (Build.VERSION.SDK_INT >= 21) {
            n3(builder);
        }
        if (Build.VERSION.SDK_INT >= 22) {
            builder.setUnderlyingNetworks(null);
        }
        if (Build.VERSION.SDK_INT >= 29) {
            builder.setMetered(false);
        }
        String str9 = this.f4525h.f10574d;
        g.a.a.c.b bVar2 = this.f4527j;
        if (bVar2 == null || (str = this.f4529l) == null) {
            g.a.a.c.b bVar3 = this.f4527j;
            string = bVar3 != null ? getString(R.string.session_ipv4string, new Object[]{str9, bVar3}) : getString(R.string.session_ipv4string, new Object[]{str9, this.f4529l});
        } else {
            string = getString(R.string.session_ipv6string, new Object[]{str9, bVar2, str});
        }
        builder.setSession(string);
        if (this.b.size() == 0) {
            y.t(R.string.warn_no_dns, new Object[0]);
        }
        this.s = a3();
        this.b.clear();
        this.c.d();
        this.f4521d.d();
        this.f4527j = null;
        this.f4529l = null;
        this.f4526i = null;
        builder.setConfigureIntent(X2());
        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) {
            y.n(R.string.tun_open_error);
            y.p(getString(R.string.error) + e7.getLocalizedMessage());
            if (Build.VERSION.SDK_INT <= 17) {
                y.n(R.string.tun_error_helpful);
                return null;
            }
            return null;
        }
    }

    public void j3() {
        V2();
    }

    @Override
    public boolean k(boolean z) {
        if (Z2() != null) {
            return Z2().k(z);
        }
        return false;
    }

    public synchronized void k3(o oVar) {
        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");
        f fVar = new f(oVar);
        this.f4530m = fVar;
        fVar.i(this);
        registerReceiver(this.f4530m, intentFilter);
        y.a(this.f4530m);
    }

    @Override
    public void l2(boolean z) {
        f fVar = this.f4530m;
        if (fVar != null) {
            fVar.k(z);
        }
    }

    public void l3(int i2, String str) {
        y.J("NEED", "need " + str, i2, g.a.a.c.e.LEVEL_WAITING_FOR_USER_INPUT);
        s3(getString(i2), getString(i2), "openvpn_newstat", 0L, g.a.a.c.e.LEVEL_WAITING_FOR_USER_INPUT, null);
    }

    public final boolean m3() {
        return ((UiModeManager) getSystemService("uimode")).getCurrentModeType() == 4;
    }

    @Override
    public void n1(long j2, long j3, long j4, long j5) {
        if (this.f4531n) {
            s3(String.format(getString(R.string.statusline_bytecount), c3(j2, false, getResources()), c3(j4 / 2, true, getResources()), c3(j3, false, getResources()), c3(j5 / 2, true, getResources())), null, "openvpn_bg", this.f4533p, g.a.a.c.e.LEVEL_CONNECTED, null);
        }
    }

    @TargetApi(21)
    public final void n3(VpnService.Builder builder) {
        boolean z = false;
        for (g.a.a.c.d dVar : this.f4525h.X) {
            if (dVar.f10602i == d.a.ORBOT) {
                z = true;
            }
        }
        if (z) {
            y.m("VPN Profile uses at least one server entry with Orbot. Setting up VPN so that OrBot is not redirected over VPN.");
        }
        if (this.f4525h.a0 && z) {
            try {
                builder.addDisallowedApplication("org.torproject.android");
            } catch (PackageManager.NameNotFoundException unused) {
                y.m("Orbot not installed?");
            }
        }
        try {
            builder.addAllowedApplication(getPackageName());
        } catch (PackageManager.NameNotFoundException e2) {
            y.p("This should not happen: " + e2.getLocalizedMessage());
        }
        g.a.a.a aVar = this.f4525h;
        if (aVar.a0) {
            y.l(R.string.disallowed_vpn_apps_info, TextUtils.join(", ", aVar.Z));
        } else {
            y.l(R.string.allowed_vpn_apps_info, TextUtils.join(", ", aVar.Z));
        }
        if (this.f4525h.b0) {
            builder.allowBypass();
            y.m("Apps may bypass VPN");
        }
    }

    public void o3(String str) {
        if (this.f4526i == null) {
            this.f4526i = 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.r;
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public void onDestroy() {
        synchronized (this.f4522e) {
            if (this.f4524g != null) {
                this.f4534q.k(true);
            }
        }
        f fVar = this.f4530m;
        if (fVar != null) {
            unregisterReceiver(fVar);
        }
        y.E(this);
        y.e();
    }

    @Override
    public void onRevoke() {
        y.n(R.string.permission_revoked);
        this.f4534q.k(false);
        V2();
    }

    @Override
    public int onStartCommand(Intent intent, int i2, int i3) {
        if (intent != null && intent.getBooleanExtra("de.blinkt.openvpn.NOTIFICATION_ALWAYS_VISIBLE", false)) {
            x = true;
        }
        y.c(this);
        y.a(this);
        this.u = new Handler(getMainLooper());
        if (intent != null && "de.blinkt.openvpn.PAUSE_VPN".equals(intent.getAction())) {
            f fVar = this.f4530m;
            if (fVar != null) {
                fVar.k(true);
            }
            return 2;
        } else if (intent != null && "de.blinkt.openvpn.RESUME_VPN".equals(intent.getAction())) {
            f fVar2 = this.f4530m;
            if (fVar2 != null) {
                fVar2.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;
            }
            y.t(R.string.building_configration, new Object[0]);
            y.J("VPN_GENERATE_CONFIG", "", R.string.building_configration, g.a.a.c.e.LEVEL_START);
            s3(y.f(this), y.f(this), "openvpn_newstat", 0L, g.a.a.c.e.LEVEL_START, null);
            if (intent != null) {
                if (intent.hasExtra(getPackageName() + ".profileUUID")) {
                    String stringExtra = intent.getStringExtra(getPackageName() + ".profileUUID");
                    g.a.a.a d2 = u.d(this, stringExtra, intent.getIntExtra(getPackageName() + ".profileVersion", 0), 100);
                    this.f4525h = d2;
                    if (Build.VERSION.SDK_INT >= 25) {
                        x3(d2);
                    }
                    if (this.f4525h != null) {
                        stopSelf(i3);
                        return 2;
                    }
                    new Thread(new c()).start();
                    u.r(this, this.f4525h);
                    y.F(this.f4525h.H());
                    return 1;
                }
            }
            this.f4525h = u.h(this);
            y.t(R.string.service_restarted, new Object[0]);
            if (this.f4525h == null) {
                Log.d("OpenVPN", "Got no last connected profile on null intent. Assuming always on.");
                g.a.a.a f2 = u.f(this);
                this.f4525h = f2;
                if (f2 == null) {
                    stopSelf(i3);
                    return 2;
                }
            }
            this.f4525h.a(this);
            if (this.f4525h != null) {
            }
        }
    }

    public void p3(String str, String str2, int i2, String str3) {
        long j2;
        int i3;
        this.f4527j = new g.a.a.c.b(str, str2);
        this.f4528k = i2;
        this.t = null;
        long c2 = g.a.a.c.b.c(str2);
        if (this.f4527j.b == 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.f4527j.b() & j2) ? 1 : ((c2 & j2) == (this.f4527j.b() & j2) ? 0 : -1));
            g.a.a.c.b bVar = this.f4527j;
            if (i4 == 0) {
                bVar.b = i3;
            } else {
                bVar.b = 32;
                if (!"p2p".equals(str3)) {
                    y.y(R.string.ip_not_cidr, str, str2, str3);
                }
            }
        }
        if (("p2p".equals(str3) && this.f4527j.b < 32) || ("net30".equals(str3) && this.f4527j.b < 30)) {
            y.y(R.string.ip_looks_like_subnet, str, str2, str3);
        }
        g.a.a.c.b bVar2 = this.f4527j;
        int i5 = bVar2.b;
        if (i5 <= 31 && Build.VERSION.SDK_INT >= 21) {
            g.a.a.c.b bVar3 = new g.a.a.c.b(bVar2.a, i5);
            bVar3.d();
            O2(bVar3, true);
        }
        this.t = str2;
    }

    @Override
    public boolean q0(String str) {
        return new g.a.a.b.b(this).c(this, str);
    }

    public void q3(String str) {
        this.f4529l = str;
    }

    public void r3(int i2) {
        this.f4528k = i2;
    }

    @Override
    public void s(String str, String str2, int i2, g.a.a.c.e eVar, Intent intent) {
        String str3;
        U2(str, eVar);
        if (this.f4524g != null || x) {
            if (eVar == g.a.a.c.e.LEVEL_CONNECTED) {
                this.f4531n = true;
                this.f4533p = System.currentTimeMillis();
                if (!m3()) {
                    str3 = "openvpn_bg";
                    s3(y.f(this), y.f(this), str3, 0L, eVar, intent);
                }
            } else {
                this.f4531n = false;
            }
            str3 = "openvpn_newstat";
            s3(y.f(this), y.f(this), str3, 0L, eVar, intent);
        }
    }

    public final void s3(String str, String str2, String str3, long j2, g.a.a.c.e eVar, Intent intent) {
        NotificationManager notificationManager = (NotificationManager) getSystemService("notification");
        int Y2 = Y2(eVar);
        Notification.Builder builder = new Notification.Builder(this);
        int i2 = str3.equals("openvpn_bg") ? -2 : str3.equals("openvpn_userreq") ? 2 : 0;
        g.a.a.a aVar = this.f4525h;
        builder.setContentTitle(aVar != null ? getString(R.string.notifcation_title, new Object[]{aVar.f10574d}) : getString(R.string.notifcation_title_notconnect));
        builder.setContentText(str);
        builder.setOnlyAlertOnce(true);
        builder.setOngoing(true);
        builder.setSmallIcon(Y2);
        builder.setContentIntent(eVar == g.a.a.c.e.LEVEL_WAITING_FOR_USER_INPUT ? PendingIntent.getActivity(this, 0, intent, 0) : X2());
        if (j2 != 0) {
            builder.setWhen(j2);
        }
        if (Build.VERSION.SDK_INT >= 16) {
            g3(i2, builder);
            S2(builder);
        }
        if (Build.VERSION.SDK_INT >= 21) {
            h3(builder, "service");
        }
        if (Build.VERSION.SDK_INT >= 26) {
            notificationManager.createNotificationChannel(new NotificationChannel(str3, str3, 3));
            builder.setChannelId(str3);
            g.a.a.a aVar2 = this.f4525h;
            if (aVar2 != null) {
                builder.setShortcutId(aVar2.H());
            }
        }
        if (str2 != null && !str2.equals("")) {
            builder.setTicker(str2);
        }
        Notification notification = builder.getNotification();
        int hashCode = str3.hashCode();
        notificationManager.notify(hashCode, notification);
        startForeground(hashCode, notification);
        String str4 = this.f4523f;
        if (str4 != null && !str3.equals(str4)) {
            notificationManager.cancel(this.f4523f.hashCode());
        }
        if (!m3() || i2 < 0) {
            return;
        }
        this.u.post(new b(str));
    }

    public final void t3() {
        String str;
        Runnable runnable;
        try {
            this.f4525h.W(this);
            String str2 = getApplicationInfo().nativeLibraryDir;
            try {
                str = getApplication().getCacheDir().getCanonicalPath();
            } catch (IOException e2) {
                e2.printStackTrace();
                str = "/tmp";
            }
            String[] a2 = x.a(this);
            this.f4532o = true;
            u3();
            this.f4532o = false;
            boolean h2 = g.a.a.a.h(this);
            if (!h2) {
                q qVar = new q(this.f4525h, this);
                if (!qVar.p(this)) {
                    V2();
                    return;
                }
                new Thread(qVar, "OpenVPNManagementThread").start();
                this.f4534q = qVar;
                y.u("started Socket Thread");
            }
            if (h2) {
                o d3 = d3();
                runnable = (Runnable) d3;
                this.f4534q = d3;
            } else {
                p pVar = new p(this, a2, str2, str);
                this.w = pVar;
                runnable = pVar;
            }
            synchronized (this.f4522e) {
                Thread thread = new Thread(runnable, "OpenVPNProcessThread");
                this.f4524g = thread;
                thread.start();
            }
            new Handler(getMainLooper()).post(new d());
        } catch (IOException e3) {
            y.s("Error writing config file", e3);
            V2();
        }
    }

    public final void u3() {
        if (this.f4534q != null) {
            Runnable runnable = this.w;
            if (runnable != null) {
                ((p) runnable).b();
            }
            if (this.f4534q.k(true)) {
                try {
                    Thread.sleep(1000L);
                } catch (InterruptedException unused) {
                }
            }
        }
        W2();
    }

    public void v3(String str) {
        int i2;
        Intent intent;
        String str2 = str.split(":", 2)[0];
        NotificationManager notificationManager = (NotificationManager) getSystemService("notification");
        Notification.Builder builder = new Notification.Builder(this);
        builder.setAutoCancel(true);
        builder.setSmallIcon(17301659);
        if (str2.equals("OPEN_URL")) {
            String str3 = str.split(":", 2)[1];
            i2 = R.string.openurl_requested;
            builder.setContentTitle(getString(R.string.openurl_requested));
            builder.setContentText(str3);
            intent = new Intent("android.intent.action.VIEW");
            intent.setData(Uri.parse(str3));
            intent.addFlags(268435456);
        } else if (!str2.equals("CR_TEXT")) {
            y.p("Unknown SSO method found: " + str2);
            return;
        } else {
            String str4 = str.split(":", 2)[1];
            i2 = R.string.crtext_requested;
            builder.setContentTitle(getString(R.string.crtext_requested));
            builder.setContentText(str4);
            intent = new Intent();
            intent.setComponent(new ComponentName(this, getPackageName() + ".activities.CredentialsPopup"));
            intent.putExtra("de.blinkt.openvpn.core.CR_TEXT_CHALLENGE", str4);
        }
        PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0);
        y.K("USER_INPUT", "waiting for user input", i2, g.a.a.c.e.LEVEL_WAITING_FOR_USER_INPUT, intent);
        builder.setContentIntent(activity);
        if (Build.VERSION.SDK_INT >= 16) {
            g3(2, builder);
        }
        if (Build.VERSION.SDK_INT >= 21) {
            h3(builder, "status");
        }
        if (Build.VERSION.SDK_INT >= 26) {
            builder.setChannelId("openvpn_userreq");
        }
        notificationManager.notify(-370124770, builder.getNotification());
    }

    public synchronized void w3() {
        if (this.f4530m != null) {
            try {
                y.C(this.f4530m);
                unregisterReceiver(this.f4530m);
            } catch (IllegalArgumentException e2) {
                e2.printStackTrace();
            }
        }
        this.f4530m = null;
    }

    public final void x3(g.a.a.a aVar) {
        if (aVar == null) {
            return;
        }
        ((ShortcutManager) getSystemService(ShortcutManager.class)).reportShortcutUsed(aVar.H());
    }
}