Spermatid v6.1.8版本的 MD5 值为:a375ce51a42d528ba6e2583c10478296

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


package aegon.chrome.net;

import aegon.chrome.base.ApiCompatibilityUtils;
import aegon.chrome.base.ContextUtils;
import aegon.chrome.base.VisibleForTesting;
import aegon.chrome.base.annotations.CalledByNative;
import aegon.chrome.base.annotations.CalledByNativeUnchecked;
import aegon.chrome.base.annotations.MainDex;
import aegon.chrome.base.compat.ApiHelperForM;
import aegon.chrome.base.compat.ApiHelperForP;
import aegon.chrome.base.metrics.RecordHistogram;
import android.annotation.TargetApi;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.TrafficStats;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.security.NetworkSecurityPolicy;
import android.util.Log;
import com.kuaishou.weapon.p0.g;
import java.io.FileDescriptor;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.SocketImpl;
import java.net.URLConnection;
import java.net.UnknownHostException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Set;

@MainDex
public class AndroidNetworkLibrary {
    private static final String TAG = "AndroidNetworkLibrary";
    private static final Set<String> sAutoDohDotServers;
    private static final Set<InetAddress> sAutoDohServers;
    private static Boolean sHaveAccessNetworkState;
    private static Boolean sHaveAccessWifiState;

    public static class SetFileDescriptor {
        private static final Method sFileDescriptorSetInt;

        static {
            try {
                sFileDescriptorSetInt = FileDescriptor.class.getMethod("setInt$", Integer.TYPE);
            } catch (NoSuchMethodException | SecurityException e10) {
                throw new RuntimeException("Unable to get FileDescriptor.setInt$", e10);
            }
        }

        private SetFileDescriptor() {
        }

        public static FileDescriptor createWithFd(int i10) {
            try {
                FileDescriptor fileDescriptor = new FileDescriptor();
                sFileDescriptorSetInt.invoke(fileDescriptor, Integer.valueOf(i10));
                return fileDescriptor;
            } catch (IllegalAccessException e10) {
                throw new RuntimeException("FileDescriptor.setInt$() failed", e10);
            } catch (InvocationTargetException e11) {
                throw new RuntimeException("FileDescriptor.setInt$() failed", e11);
            }
        }
    }

    public static class SocketFd extends Socket {

        public static class SocketImplFd extends SocketImpl {
            public SocketImplFd(FileDescriptor fileDescriptor) {
                ((SocketImpl) this).fd = fileDescriptor;
            }

            @Override
            public void accept(SocketImpl socketImpl) {
                throw new RuntimeException("accept not implemented");
            }

            @Override
            public int available() {
                throw new RuntimeException("accept not implemented");
            }

            @Override
            public void bind(InetAddress inetAddress, int i10) {
                throw new RuntimeException("accept not implemented");
            }

            @Override
            public void close() {
            }

            @Override
            public void connect(InetAddress inetAddress, int i10) {
                throw new RuntimeException("connect not implemented");
            }

            @Override
            public void create(boolean z10) {
            }

            @Override
            public InputStream getInputStream() {
                throw new RuntimeException("getInputStream not implemented");
            }

            @Override
            public Object getOption(int i10) {
                throw new RuntimeException("getOption not implemented");
            }

            @Override
            public OutputStream getOutputStream() {
                throw new RuntimeException("getOutputStream not implemented");
            }

            @Override
            public void listen(int i10) {
                throw new RuntimeException("listen not implemented");
            }

            @Override
            public void sendUrgentData(int i10) {
                throw new RuntimeException("sendUrgentData not implemented");
            }

            @Override
            public void setOption(int i10, Object obj) {
                throw new RuntimeException("setOption not implemented");
            }

            @Override
            public void connect(SocketAddress socketAddress, int i10) {
                throw new RuntimeException("connect not implemented");
            }

            @Override
            public void connect(String str, int i10) {
                throw new RuntimeException("connect not implemented");
            }
        }

        public SocketFd(FileDescriptor fileDescriptor) {
            super(new SocketImplFd(fileDescriptor));
        }
    }

    static {
        HashSet hashSet = new HashSet();
        sAutoDohServers = hashSet;
        HashSet hashSet2 = new HashSet();
        sAutoDohDotServers = hashSet2;
        try {
            hashSet.add(InetAddress.getByName("8.8.8.8"));
            hashSet.add(InetAddress.getByName("8.8.4.4"));
            hashSet.add(InetAddress.getByName("2001:4860:4860::8888"));
            hashSet.add(InetAddress.getByName("2001:4860:4860::8844"));
            hashSet.add(InetAddress.getByName("1.1.1.1"));
            hashSet.add(InetAddress.getByName("1.0.0.1"));
            hashSet.add(InetAddress.getByName("2606:4700:4700::1111"));
            hashSet.add(InetAddress.getByName("2606:4700:4700::1001"));
            hashSet.add(InetAddress.getByName("9.9.9.9"));
            hashSet.add(InetAddress.getByName("149.112.112.112"));
            hashSet.add(InetAddress.getByName("2620:fe::fe"));
            hashSet.add(InetAddress.getByName("2620:fe::9"));
            hashSet2.add("dns.google");
            hashSet2.add("1dot1dot1dot1.cloudflare-dns.com");
            hashSet2.add("cloudflare-dns.com");
            hashSet2.add("dns.quad9.net");
        } catch (UnknownHostException e10) {
            throw new RuntimeException("Failed to parse IP addresses", e10);
        }
    }

    @CalledByNativeUnchecked
    public static void addTestRootCertificate(byte[] bArr) {
        X509Util.addTestRootCertificate(bArr);
    }

    @CalledByNativeUnchecked
    public static void clearTestRootCertificates() {
        X509Util.clearTestRootCertificates();
    }

    @CalledByNative
    @TargetApi(23)
    private static byte[][] getDnsServers() {
        ConnectivityManager connectivityManager;
        Network activeNetwork;
        LinkProperties linkProperties;
        int i10;
        boolean z10;
        if (haveAccessNetworkState() && (connectivityManager = (ConnectivityManager) ContextUtils.getApplicationContext().getSystemService("connectivity")) != null && (activeNetwork = ApiHelperForM.getActiveNetwork(connectivityManager)) != null && (linkProperties = connectivityManager.getLinkProperties(activeNetwork)) != null) {
            List<InetAddress> dnsServers = linkProperties.getDnsServers();
            Iterator<InetAddress> it = dnsServers.iterator();
            while (true) {
                if (!it.hasNext()) {
                    z10 = false;
                    break;
                }
                if (sAutoDohServers.contains(it.next())) {
                    z10 = true;
                    break;
                }
            }
            if (isPrivateDnsActive(linkProperties)) {
                String privateDnsServerName = getPrivateDnsServerName(linkProperties);
                if (privateDnsServerName != null) {
                    z10 = sAutoDohDotServers.contains(privateDnsServerName.toLowerCase(Locale.US));
                }
                RecordHistogram.recordBooleanHistogram("Net.DNS.Android.DotExplicit", privateDnsServerName != null);
                RecordHistogram.recordBooleanHistogram("Net.DNS.Android.AutoDohPrivate", z10);
                return (byte[][]) Array.newInstance((Class<?>) byte.class, 1, 1);
            }
            RecordHistogram.recordBooleanHistogram("Net.DNS.Android.AutoDohPublic", z10);
            byte[][] bArr = new byte[dnsServers.size()];
            for (i10 = 0; i10 < dnsServers.size(); i10++) {
                bArr[i10] = dnsServers.get(i10).getAddress();
            }
            return bArr;
        }
        return (byte[][]) Array.newInstance((Class<?>) byte.class, 0, 0);
    }

    @CalledByNative
    @TargetApi(23)
    private static boolean getIsCaptivePortal() {
        ConnectivityManager connectivityManager;
        Network activeNetwork;
        NetworkCapabilities networkCapabilities;
        return (Build.VERSION.SDK_INT < 23 || (connectivityManager = (ConnectivityManager) ContextUtils.getApplicationContext().getSystemService("connectivity")) == null || (activeNetwork = ApiHelperForM.getActiveNetwork(connectivityManager)) == null || (networkCapabilities = connectivityManager.getNetworkCapabilities(activeNetwork)) == null || !networkCapabilities.hasCapability(17)) ? false : true;
    }

    @CalledByNative
    private static boolean getIsRoaming() {
        NetworkInfo activeNetworkInfo = ((ConnectivityManager) ContextUtils.getApplicationContext().getSystemService("connectivity")).getActiveNetworkInfo();
        if (activeNetworkInfo == null) {
            return false;
        }
        return activeNetworkInfo.isRoaming();
    }

    @CalledByNative
    public static String getMimeTypeFromExtension(String str) {
        return URLConnection.guessContentTypeFromName("foo." + str);
    }

    @CalledByNative
    private static String getNetworkCountryIso() {
        return AndroidTelephonyManagerBridge.getInstance().getNetworkCountryIso();
    }

    @CalledByNative
    private static String getNetworkOperator() {
        return AndroidTelephonyManagerBridge.getInstance().getNetworkOperator();
    }

    private static String getPrivateDnsServerName(LinkProperties linkProperties) {
        if (Build.VERSION.SDK_INT < 28 || linkProperties == null) {
            return null;
        }
        return ApiHelperForP.getPrivateDnsServerName(linkProperties);
    }

    @CalledByNative
    private static String getSimOperator() {
        return AndroidTelephonyManagerBridge.getInstance().getSimOperator();
    }

    @CalledByNative
    public static String getWifiSSID() {
        return "";
    }

    @CalledByNative
    public static int getWifiSignalLevel(int i10) {
        Intent registerReceiver;
        int intExtra;
        int calculateSignalLevel;
        try {
            registerReceiver = ContextUtils.getApplicationContext().registerReceiver(null, new IntentFilter("android.net.wifi.RSSI_CHANGED"));
        } catch (IllegalArgumentException | Exception unused) {
        }
        if (registerReceiver != null && (intExtra = registerReceiver.getIntExtra("newRssi", Integer.MIN_VALUE)) != Integer.MIN_VALUE && (calculateSignalLevel = WifiManager.calculateSignalLevel(intExtra, i10)) >= 0 && calculateSignalLevel < i10) {
            return calculateSignalLevel;
        }
        return -1;
    }

    private static boolean haveAccessNetworkState() {
        if (sHaveAccessNetworkState == null) {
            sHaveAccessNetworkState = Boolean.valueOf(ApiCompatibilityUtils.checkPermission(ContextUtils.getApplicationContext(), g.f16353b, Process.myPid(), Process.myUid()) == 0);
        }
        return sHaveAccessNetworkState.booleanValue();
    }

    private static boolean haveAccessWifiState() {
        if (sHaveAccessWifiState == null) {
            sHaveAccessWifiState = Boolean.valueOf(ApiCompatibilityUtils.checkPermission(ContextUtils.getApplicationContext(), g.f16355d, Process.myPid(), Process.myUid()) == 0);
        }
        return sHaveAccessWifiState.booleanValue();
    }

    @CalledByNative
    public static boolean haveOnlyLoopbackAddresses() {
        try {
            Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
            if (networkInterfaces == null) {
                return false;
            }
            while (networkInterfaces.hasMoreElements()) {
                NetworkInterface nextElement = networkInterfaces.nextElement();
                try {
                    if (nextElement.isUp() && !nextElement.isLoopback()) {
                        return false;
                    }
                } catch (SocketException unused) {
                }
            }
            return true;
        } catch (Exception e10) {
            Log.w(TAG, "could not get network interfaces: " + e10);
            return false;
        }
    }

    @CalledByNative
    private static boolean isCleartextPermitted(String str) {
        try {
            return NetworkSecurityPolicyProxy.getInstance().isCleartextTrafficPermitted(str);
        } catch (IllegalArgumentException unused) {
            return NetworkSecurityPolicyProxy.getInstance().isCleartextTrafficPermitted();
        }
    }

    public static boolean isPrivateDnsActive(LinkProperties linkProperties) {
        if (Build.VERSION.SDK_INT < 28 || linkProperties == null) {
            return false;
        }
        return ApiHelperForP.isPrivateDnsActive(linkProperties);
    }

    @CalledByNative
    private static void tagSocket(int i10, int i11, int i12) {
        ParcelFileDescriptor adoptFd;
        FileDescriptor fileDescriptor;
        int threadStatsTag = TrafficStats.getThreadStatsTag();
        if (i12 != threadStatsTag) {
            TrafficStats.setThreadStatsTag(i12);
        }
        if (i11 != -1) {
            ThreadStatsUid.set(i11);
        }
        if (Build.VERSION.SDK_INT < 23) {
            adoptFd = null;
            fileDescriptor = SetFileDescriptor.createWithFd(i10);
        } else {
            adoptFd = ParcelFileDescriptor.adoptFd(i10);
            fileDescriptor = adoptFd.getFileDescriptor();
        }
        SocketFd socketFd = new SocketFd(fileDescriptor);
        TrafficStats.tagSocket(socketFd);
        socketFd.close();
        if (adoptFd != null) {
            adoptFd.detachFd();
        }
        if (i12 != threadStatsTag) {
            TrafficStats.setThreadStatsTag(threadStatsTag);
        }
        if (i11 != -1) {
            ThreadStatsUid.clear();
        }
    }

    @CalledByNative
    public static AndroidCertVerifyResult verifyServerCertificates(byte[][] bArr, String str, String str2) {
        try {
            return X509Util.verifyServerCertificates(bArr, str, str2);
        } catch (IllegalArgumentException unused) {
            return new AndroidCertVerifyResult(-1);
        } catch (KeyStoreException unused2) {
            return new AndroidCertVerifyResult(-1);
        } catch (NoSuchAlgorithmException unused3) {
            return new AndroidCertVerifyResult(-1);
        } catch (Throwable unused4) {
            return new AndroidCertVerifyResult(-1);
        }
    }

    public static class NetworkSecurityPolicyProxy {
        private static NetworkSecurityPolicyProxy sInstance = new NetworkSecurityPolicyProxy();

        public static NetworkSecurityPolicyProxy getInstance() {
            return sInstance;
        }

        @VisibleForTesting
        public static void setInstanceForTesting(NetworkSecurityPolicyProxy networkSecurityPolicyProxy) {
            sInstance = networkSecurityPolicyProxy;
        }

        @TargetApi(24)
        public boolean isCleartextTrafficPermitted(String str) {
            if (Build.VERSION.SDK_INT < 24) {
                return isCleartextTrafficPermitted();
            }
            return NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted(str);
        }

        @TargetApi(23)
        public boolean isCleartextTrafficPermitted() {
            if (Build.VERSION.SDK_INT < 23) {
                return true;
            }
            return NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted();
        }
    }
}