package XnFJ5_9.Ft6VRog_36;

import Nm6q_10.FSaI4_7;
import Nm6q_10.G83uNX_24;
import Nm6q_10.LGe8pk_15;
import XnFJ5_9.DtqPmDY_31;
import XnFJ5_9.SI64pbG_23;
import XnFJ5_9.ViqFd_33;
import androidx.recyclerview.widget.RecyclerView;
import java.io.Closeable;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.IDN;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.security.AccessControlException;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
/* compiled from: Util.java */
/* loaded from: classes.dex */
public final class X6FRs_4 {

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public static final Method f1613KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public static final Comparator<String> f1614KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public static final TimeZone f1615KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public static final Pattern f1616KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public static final byte[] f1617KQgRr5e_0 = new byte[0];

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public static final String[] f1618KQgRr5e_0 = new String[0];
    public static final SI64pbG_23 KQgRr5e_0 = SI64pbG_23.KQgRr5e_0(new String[0]);

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public static final ViqFd_33 f1612KQgRr5e_0 = ViqFd_33.KQgRr5e_0(null, f1617KQgRr5e_0);

    static {
        Method method = null;
        DtqPmDY_31.KQgRr5e_0(null, f1617KQgRr5e_0);
        LGe8pk_15.KQgRr5e_0(FSaI4_7.QxJ9d_1("efbbbf"), FSaI4_7.QxJ9d_1("feff"), FSaI4_7.QxJ9d_1("fffe"), FSaI4_7.QxJ9d_1("0000ffff"), FSaI4_7.QxJ9d_1("ffff0000"));
        Charset.forName("UTF-32BE");
        Charset.forName("UTF-32LE");
        f1615KQgRr5e_0 = TimeZone.getTimeZone("GMT");
        f1614KQgRr5e_0 = KQgRr5e_0.KQgRr5e_0;
        try {
            method = Throwable.class.getDeclaredMethod("addSuppressed", Throwable.class);
        } catch (Exception unused) {
        }
        f1613KQgRr5e_0 = method;
        f1616KQgRr5e_0 = Pattern.compile("([0-9a-fA-F]*:[0-9a-fA-F:.]*)|([\\d.]+)");
    }

    public static int KQgRr5e_0(char c) {
        if (c < '0' || c > '9') {
            char c2 = 'a';
            if (c < 'a' || c > 'f') {
                c2 = 'A';
                if (c < 'A' || c > 'F') {
                    return -1;
                }
            }
            return (c - c2) + 10;
        }
        return c - '0';
    }

    public static void KQgRr5e_0(Throwable th, Throwable th2) {
        Method method = f1613KQgRr5e_0;
        if (method != null) {
            try {
                method.invoke(th, th2);
            } catch (IllegalAccessException | InvocationTargetException unused) {
            }
        }
    }

    public static boolean QxJ9d_1(G83uNX_24 g83uNX_24, int i, TimeUnit timeUnit) throws IOException {
        long nanoTime = System.nanoTime();
        long KQgRr5e_02 = g83uNX_24.KQgRr5e_0().m174KQgRr5e_0() ? g83uNX_24.KQgRr5e_0().KQgRr5e_0() - nanoTime : Long.MAX_VALUE;
        g83uNX_24.KQgRr5e_0().KQgRr5e_0(Math.min(KQgRr5e_02, timeUnit.toNanos(i)) + nanoTime);
        try {
            Nm6q_10.X6FRs_4 x6FRs_4 = new Nm6q_10.X6FRs_4();
            while (g83uNX_24.KQgRr5e_0(x6FRs_4, 8192L) != -1) {
                x6FRs_4.KQgRr5e_0();
            }
            if (KQgRr5e_02 == RecyclerView.FOREVER_NS) {
                g83uNX_24.KQgRr5e_0().m172KQgRr5e_0();
            } else {
                g83uNX_24.KQgRr5e_0().KQgRr5e_0(nanoTime + KQgRr5e_02);
            }
            return true;
        } catch (InterruptedIOException unused) {
            if (KQgRr5e_02 == RecyclerView.FOREVER_NS) {
                g83uNX_24.KQgRr5e_0().m172KQgRr5e_0();
            } else {
                g83uNX_24.KQgRr5e_0().KQgRr5e_0(nanoTime + KQgRr5e_02);
            }
            return false;
        } catch (Throwable th) {
            if (KQgRr5e_02 == RecyclerView.FOREVER_NS) {
                g83uNX_24.KQgRr5e_0().m172KQgRr5e_0();
            } else {
                g83uNX_24.KQgRr5e_0().KQgRr5e_0(nanoTime + KQgRr5e_02);
            }
            throw th;
        }
    }

    public static void KQgRr5e_0(long j, long j2, long j3) {
        if ((j2 | j3) < 0 || j2 > j || j - j2 < j3) {
            throw new ArrayIndexOutOfBoundsException();
        }
    }

    public static void KQgRr5e_0(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception unused) {
            }
        }
    }

    public static void KQgRr5e_0(Socket socket) {
        if (socket != null) {
            try {
                socket.close();
            } catch (AssertionError e) {
                if (!KQgRr5e_0(e)) {
                    throw e;
                }
            } catch (RuntimeException e2) {
                throw e2;
            } catch (Exception unused) {
            }
        }
    }

    public static boolean KQgRr5e_0(G83uNX_24 g83uNX_24, int i, TimeUnit timeUnit) {
        try {
            return QxJ9d_1(g83uNX_24, i, timeUnit);
        } catch (IOException unused) {
            return false;
        }
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public static <T> List<T> m731KQgRr5e_0(List<T> list) {
        return Collections.unmodifiableList(new ArrayList(list));
    }

    public static <K, V> Map<K, V> KQgRr5e_0(Map<K, V> map) {
        if (map.isEmpty()) {
            return Collections.emptyMap();
        }
        return Collections.unmodifiableMap(new LinkedHashMap(map));
    }

    @SafeVarargs
    public static <T> List<T> KQgRr5e_0(T... tArr) {
        return Collections.unmodifiableList(Arrays.asList((Object[]) tArr.clone()));
    }

    public static int QxJ9d_1(String str, int i, int i2) {
        for (int i3 = i2 - 1; i3 >= i; i3--) {
            char charAt = str.charAt(i3);
            if (charAt != '\t' && charAt != '\n' && charAt != '\f' && charAt != '\r' && charAt != ' ') {
                return i3 + 1;
            }
        }
        return i;
    }

    public static ThreadFactory KQgRr5e_0(final String str, final boolean z) {
        return new ThreadFactory() { // from class: XnFJ5_9.Ft6VRog_36.QxJ9d_1
            @Override // java.util.concurrent.ThreadFactory
            public final Thread newThread(Runnable runnable) {
                return X6FRs_4.KQgRr5e_0(str, z, runnable);
            }
        };
    }

    public static boolean QxJ9d_1(String str) {
        return f1616KQgRr5e_0.matcher(str).matches();
    }

    public static /* synthetic */ Thread KQgRr5e_0(String str, boolean z, Runnable runnable) {
        Thread thread = new Thread(runnable, str);
        thread.setDaemon(z);
        return thread;
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public static String[] m733KQgRr5e_0(Comparator<? super String> comparator, String[] strArr, String[] strArr2) {
        ArrayList arrayList = new ArrayList();
        for (String str : strArr) {
            int length = strArr2.length;
            int i = 0;
            while (true) {
                if (i >= length) {
                    break;
                } else if (comparator.compare(str, strArr2[i]) == 0) {
                    arrayList.add(str);
                    break;
                } else {
                    i++;
                }
            }
        }
        return (String[]) arrayList.toArray(new String[arrayList.size()]);
    }

    public static boolean KQgRr5e_0(Comparator<String> comparator, String[] strArr, String[] strArr2) {
        if (strArr != null && strArr2 != null && strArr.length != 0 && strArr2.length != 0) {
            for (String str : strArr) {
                for (String str2 : strArr2) {
                    if (comparator.compare(str, str2) == 0) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

    public static String KQgRr5e_0(XnFJ5_9.G83uNX_24 g83uNX_24, boolean z) {
        String IFxWkV_52;
        if (g83uNX_24.IFxWkV_5().contains(":")) {
            IFxWkV_52 = "[" + g83uNX_24.IFxWkV_5() + "]";
        } else {
            IFxWkV_52 = g83uNX_24.IFxWkV_5();
        }
        if (z || g83uNX_24.KQgRr5e_0() != XnFJ5_9.G83uNX_24.KQgRr5e_0(g83uNX_24.Xgtqvk_8())) {
            return IFxWkV_52 + ":" + g83uNX_24.KQgRr5e_0();
        }
        return IFxWkV_52;
    }

    public static boolean KQgRr5e_0(AssertionError assertionError) {
        return (assertionError.getCause() == null || assertionError.getMessage() == null || !assertionError.getMessage().contains("getsockname failed")) ? false : true;
    }

    public static int KQgRr5e_0(Comparator<String> comparator, String[] strArr, String str) {
        int length = strArr.length;
        for (int i = 0; i < length; i++) {
            if (comparator.compare(strArr[i], str) == 0) {
                return i;
            }
        }
        return -1;
    }

    public static String[] KQgRr5e_0(String[] strArr, String str) {
        int length = strArr.length + 1;
        String[] strArr2 = new String[length];
        System.arraycopy(strArr, 0, strArr2, 0, strArr.length);
        strArr2[length - 1] = str;
        return strArr2;
    }

    public static int KQgRr5e_0(String str, int i, int i2) {
        while (i < i2) {
            char charAt = str.charAt(i);
            if (charAt != '\t' && charAt != '\n' && charAt != '\f' && charAt != '\r' && charAt != ' ') {
                return i;
            }
            i++;
        }
        return i2;
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public static String m729KQgRr5e_0(String str, int i, int i2) {
        int KQgRr5e_02 = KQgRr5e_0(str, i, i2);
        return str.substring(KQgRr5e_02, QxJ9d_1(str, KQgRr5e_02, i2));
    }

    public static int KQgRr5e_0(String str, int i, int i2, String str2) {
        while (i < i2) {
            if (str2.indexOf(str.charAt(i)) != -1) {
                return i;
            }
            i++;
        }
        return i2;
    }

    public static int KQgRr5e_0(String str, int i, int i2, char c) {
        while (i < i2) {
            if (str.charAt(i) == c) {
                return i;
            }
            i++;
        }
        return i2;
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public static String m728KQgRr5e_0(String str) {
        InetAddress m730KQgRr5e_0;
        if (str.contains(":")) {
            if (str.startsWith("[") && str.endsWith("]")) {
                m730KQgRr5e_0 = m730KQgRr5e_0(str, 1, str.length() - 1);
            } else {
                m730KQgRr5e_0 = m730KQgRr5e_0(str, 0, str.length());
            }
            if (m730KQgRr5e_0 == null) {
                return null;
            }
            byte[] address = m730KQgRr5e_0.getAddress();
            if (address.length == 16) {
                return KQgRr5e_0(address);
            }
            if (address.length == 4) {
                return m730KQgRr5e_0.getHostAddress();
            }
            throw new AssertionError("Invalid IPv6 address: '" + str + "'");
        }
        try {
            String lowerCase = IDN.toASCII(str).toLowerCase(Locale.US);
            if (lowerCase.isEmpty()) {
                return null;
            }
            if (m732KQgRr5e_0(lowerCase)) {
                return null;
            }
            return lowerCase;
        } catch (IllegalArgumentException unused) {
            return null;
        }
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public static boolean m732KQgRr5e_0(String str) {
        for (int i = 0; i < str.length(); i++) {
            char charAt = str.charAt(i);
            if (charAt <= 31 || charAt >= 127 || " #%/:?@[\\]".indexOf(charAt) != -1) {
                return true;
            }
        }
        return false;
    }

    public static int KQgRr5e_0(String str) {
        int length = str.length();
        for (int i = 0; i < length; i++) {
            char charAt = str.charAt(i);
            if (charAt <= 31 || charAt >= 127) {
                return i;
            }
        }
        return -1;
    }

    public static String KQgRr5e_0(String str, Object... objArr) {
        return String.format(Locale.US, str, objArr);
    }

    /* JADX WARN: Code restructure failed: missing block: B:41:0x0079, code lost:
        return null;
     */
    /* JADX WARN: Removed duplicated region for block: B:31:0x004f  */
    @Nullable
    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static InetAddress m730KQgRr5e_0(String str, int i, int i2) {
        int i3;
        byte[] bArr = new byte[16];
        int i4 = 0;
        int i5 = -1;
        int i6 = -1;
        while (true) {
            if (i < i2) {
                if (i4 != 16) {
                    int i7 = i + 2;
                    if (i7 <= i2 && str.regionMatches(i, "::", 0, 2)) {
                        if (i5 == -1) {
                            i4 += 2;
                            i5 = i4;
                            if (i7 != i2) {
                                i6 = i7;
                                i = i6;
                                int i8 = 0;
                                while (i < i2) {
                                }
                                i3 = i - i6;
                                if (i3 == 0) {
                                    break;
                                }
                                break;
                            }
                            break;
                        }
                        return null;
                    }
                    if (i4 != 0) {
                        if (str.regionMatches(i, ":", 0, 1)) {
                            i++;
                        } else if (!str.regionMatches(i, ".", 0, 1) || !KQgRr5e_0(str, i6, i2, bArr, i4 - 2)) {
                            return null;
                        } else {
                            i4 += 2;
                        }
                    }
                    i6 = i;
                    i = i6;
                    int i82 = 0;
                    while (i < i2) {
                        int KQgRr5e_02 = KQgRr5e_0(str.charAt(i));
                        if (KQgRr5e_02 == -1) {
                            break;
                        }
                        i82 = (i82 << 4) + KQgRr5e_02;
                        i++;
                    }
                    i3 = i - i6;
                    if (i3 == 0 || i3 > 4) {
                        break;
                    }
                    int i9 = i4 + 1;
                    bArr[i4] = (byte) ((i82 >>> 8) & 255);
                    i4 = i9 + 1;
                    bArr[i9] = (byte) (i82 & 255);
                } else {
                    return null;
                }
            } else {
                break;
            }
        }
        if (i4 != 16) {
            if (i5 == -1) {
                return null;
            }
            int i10 = i4 - i5;
            System.arraycopy(bArr, i5, bArr, 16 - i10, i10);
            Arrays.fill(bArr, i5, (16 - i4) + i5, (byte) 0);
        }
        try {
            return InetAddress.getByAddress(bArr);
        } catch (UnknownHostException unused) {
            throw new AssertionError();
        }
    }

    public static boolean KQgRr5e_0(String str, int i, int i2, byte[] bArr, int i3) {
        int i4 = i3;
        while (i < i2) {
            if (i4 == bArr.length) {
                return false;
            }
            if (i4 != i3) {
                if (str.charAt(i) != '.') {
                    return false;
                }
                i++;
            }
            int i5 = i;
            int i6 = 0;
            while (i5 < i2) {
                char charAt = str.charAt(i5);
                if (charAt < '0' || charAt > '9') {
                    break;
                } else if ((i6 == 0 && i != i5) || (i6 = ((i6 * 10) + charAt) - 48) > 255) {
                    return false;
                } else {
                    i5++;
                }
            }
            if (i5 - i == 0) {
                return false;
            }
            bArr[i4] = (byte) i6;
            i4++;
            i = i5;
        }
        return i4 == i3 + 4;
    }

    public static String KQgRr5e_0(byte[] bArr) {
        int i = 0;
        int i2 = -1;
        int i3 = 0;
        int i4 = 0;
        while (i3 < bArr.length) {
            int i5 = i3;
            while (i5 < 16 && bArr[i5] == 0 && bArr[i5 + 1] == 0) {
                i5 += 2;
            }
            int i6 = i5 - i3;
            if (i6 > i4 && i6 >= 4) {
                i2 = i3;
                i4 = i6;
            }
            i3 = i5 + 2;
        }
        Nm6q_10.X6FRs_4 x6FRs_4 = new Nm6q_10.X6FRs_4();
        while (i < bArr.length) {
            if (i == i2) {
                x6FRs_4.KQgRr5e_0(58);
                i += i4;
                if (i == 16) {
                    x6FRs_4.KQgRr5e_0(58);
                }
            } else {
                if (i > 0) {
                    x6FRs_4.KQgRr5e_0(58);
                }
                x6FRs_4.KQgRr5e_0(((bArr[i] & 255) << 8) | (bArr[i + 1] & 255));
                i += 2;
            }
        }
        return x6FRs_4.QxJ9d_1();
    }

    public static X509TrustManager KQgRr5e_0() {
        try {
            TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
            trustManagerFactory.init((KeyStore) null);
            TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
            if (trustManagers.length == 1 && (trustManagers[0] instanceof X509TrustManager)) {
                return (X509TrustManager) trustManagers[0];
            }
            throw new IllegalStateException("Unexpected default trust managers:" + Arrays.toString(trustManagers));
        } catch (GeneralSecurityException unused) {
            throw new AssertionError("No System TLS");
        }
    }

    public static SI64pbG_23 KQgRr5e_0(List<XnFJ5_9.Ft6VRog_36.Nm6q_10.PGPF6hQ_2> list) {
        SI64pbG_23.KQgRr5e_0 kQgRr5e_0 = new SI64pbG_23.KQgRr5e_0();
        for (XnFJ5_9.Ft6VRog_36.Nm6q_10.PGPF6hQ_2 pGPF6hQ_2 : list) {
            PGPF6hQ_2.KQgRr5e_0.KQgRr5e_0(kQgRr5e_0, pGPF6hQ_2.f1587KQgRr5e_0.Mqv2r_3(), pGPF6hQ_2.QxJ9d_1.Mqv2r_3());
        }
        return kQgRr5e_0.KQgRr5e_0();
    }

    public static List<XnFJ5_9.Ft6VRog_36.Nm6q_10.PGPF6hQ_2> KQgRr5e_0(SI64pbG_23 sI64pbG_23) {
        ArrayList arrayList = new ArrayList();
        for (int i = 0; i < sI64pbG_23.KQgRr5e_0(); i++) {
            arrayList.add(new XnFJ5_9.Ft6VRog_36.Nm6q_10.PGPF6hQ_2(sI64pbG_23.KQgRr5e_0(i), sI64pbG_23.QxJ9d_1(i)));
        }
        return arrayList;
    }

    public static String KQgRr5e_0(String str, @Nullable String str2) {
        try {
            String property = System.getProperty(str);
            return property != null ? property : str2;
        } catch (AccessControlException unused) {
            return str2;
        }
    }

    public static boolean KQgRr5e_0(XnFJ5_9.G83uNX_24 g83uNX_24, XnFJ5_9.G83uNX_24 g83uNX_242) {
        return g83uNX_24.IFxWkV_5().equals(g83uNX_242.IFxWkV_5()) && g83uNX_24.KQgRr5e_0() == g83uNX_242.KQgRr5e_0() && g83uNX_24.Xgtqvk_8().equals(g83uNX_242.Xgtqvk_8());
    }
}
