速狼加速器 v1.3.05版本的 MD5 值为:16b5e8af5c3774d85c1aa8bd4f624d0b

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


package com.lzz.youtu.NetworkMonitor;

import android.os.Build;
import com.lzz.youtu.NetworkFramework.UdpDatagram;
import com.lzz.youtu.NetworkMonitor.NetWorkMonitorManager;
import com.lzz.youtu.data.LogUtils;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class NetworkChangeNotification implements NetWorkMonitorManager.NetWorkStatusChange, Runnable {
    private static final NetworkChangeNotification instance = new NetworkChangeNotification();
    private NetWorkState lastSate;
    private Thread mThread;
    private Lock lock = new ReentrantLock();
    private List<NetworkChangeNotify> handlers = new LinkedList();
    private Map<Integer, AdapterInfo> adapteres = new ConcurrentHashMap();
    private List<String> dnsDomainList = new LinkedList();
    private List<String> dnsServerList = new LinkedList();
    private AtomicBoolean testing = new AtomicBoolean(false);
    private AtomicBoolean dnsResult = new AtomicBoolean(false);
    private Object resultEvent = new Object();

    public enum NetWorkState {
        AVAILABLE,
        NONE,
        WIFI,
        CELLULAR,
        ETHERNET,
        VPN
    }

    public interface NetworkChangeNotify {
        void onNetworkChange(NetWorkState netWorkState);
    }

    @Override
    public void onNetworkStatusChange(int i) {
    }

    public static NetworkChangeNotification getInstance() {
        return instance;
    }

    public NetworkChangeNotification() {
        NetWorkMonitorManager.getInstance().register(this);
        this.dnsDomainList.add("www.baidu.com");
        this.dnsDomainList.add("www.apple.com");
        this.dnsServerList.add("8.8.8.8");
        this.dnsServerList.add("8.8.4.4");
        this.dnsServerList.add("180.76.76.76");
        Thread thread = new Thread(this);
        this.mThread = thread;
        thread.start();
    }

    public NetWorkState getCurNetworkStateV1() {
        NetWorkState curNetworkState = getCurNetworkState();
        if (curNetworkState != NetWorkState.NONE && sendDns()) {
            LogUtils.dLog(getClass().getName(), "[getCurNetworkStateV1]:" + curNetworkState);
            return curNetworkState;
        }
        LogUtils.dLog(getClass().getName(), "[getCurNetworkStateV1]:" + NetWorkState.NONE);
        return NetWorkState.NONE;
    }

    public NetWorkState getCurNetworkState() {
        NetWorkState netWorkState = NetWorkState.NONE;
        if (this.adapteres.size() > 0) {
            Iterator<Map.Entry<Integer, AdapterInfo>> it2 = this.adapteres.entrySet().iterator();
            while (true) {
                if (!it2.hasNext()) {
                    break;
                }
                Map.Entry<Integer, AdapterInfo> next = it2.next();
                if (next.getValue().state != NetWorkState.VPN) {
                    LogUtils.eLog(getClass().getName(), "id:" + next.getKey() + "  valueL" + next.getValue().state);
                    netWorkState = next.getValue().state;
                    break;
                }
            }
        } else if (Build.VERSION.SDK_INT < 21) {
            int currentNetworkState = NetWorkMonitorManager.getCurrentNetworkState();
            LogUtils.eLog(getClass().getName(), "getCurNetworkState: net:" + currentNetworkState);
            if (currentNetworkState == 1) {
                netWorkState = NetWorkState.WIFI;
            } else if (currentNetworkState == 2 || currentNetworkState == 3 || currentNetworkState == 4) {
                netWorkState = NetWorkState.CELLULAR;
            }
        }
        LogUtils.dLog(getClass().getName(), "[getCurNetworkState]:" + netWorkState);
        return netWorkState;
    }

    public boolean networkIsBad() {
        return getCurNetworkState() == NetWorkState.NONE;
    }

    public void removeNotify(NetworkChangeNotify networkChangeNotify) {
        this.lock.lock();
        this.handlers.remove(networkChangeNotify);
        this.lock.unlock();
    }

    public void addNotify(NetworkChangeNotify networkChangeNotify) {
        this.lock.lock();
        if (!this.handlers.contains(networkChangeNotify)) {
            this.handlers.add(networkChangeNotify);
        }
        this.lock.unlock();
    }

    private void notification(NetWorkState netWorkState) {
        LogUtils.eLog(getClass().getName(), "[notification]: state:" + netWorkState);
        if (netWorkState != this.lastSate) {
            this.lastSate = netWorkState;
            this.lock.lock();
            Iterator<NetworkChangeNotify> it2 = this.handlers.iterator();
            while (it2.hasNext()) {
                it2.next().onNetworkChange(netWorkState);
            }
            this.lock.unlock();
        }
    }

    @Override
    public void onAvailable(int i) {
        this.adapteres.put(Integer.valueOf(i), new AdapterInfo(i));
    }

    @Override
    public void onLost(int i) {
        this.adapteres.remove(Integer.valueOf(i));
        notification(getCurNetworkState());
    }

    @Override
    public void onCapabilitiesChanged(int i, int i2) {
        AdapterInfo adapterInfo = this.adapteres.get(Integer.valueOf(i));
        if (adapterInfo == null) {
            adapterInfo = new AdapterInfo(i);
            this.adapteres.put(Integer.valueOf(i), adapterInfo);
        }
        LogUtils.dLog(getClass().getName(), "onCapabilitiesChanged: type:" + i2);
        if (i2 == 0) {
            adapterInfo.state = NetWorkState.CELLULAR;
        } else if (i2 == 1) {
            adapterInfo.state = NetWorkState.WIFI;
        } else if (i2 == 3) {
            adapterInfo.state = NetWorkState.ETHERNET;
        } else if (i2 == 4) {
            adapterInfo.state = NetWorkState.VPN;
        }
        notification(getCurNetworkState());
    }

    private boolean sendDns() {
        if (this.testing.compareAndSet(false, true)) {
            Thread thread = new Thread(this);
            this.mThread = thread;
            thread.start();
        }
        synchronized (this.resultEvent) {
            try {
                this.resultEvent.wait(2000L);
            } catch (InterruptedException unused) {
            }
        }
        this.testing.set(false);
        return this.dnsResult.get();
    }

    @Override
    public void run() {
        for (String str : this.dnsDomainList) {
            Iterator<String> it2 = this.dnsServerList.iterator();
            while (it2.hasNext()) {
                if (UdpDatagram.checkDns(str, it2.next())) {
                    this.dnsResult.set(true);
                    synchronized (this.resultEvent) {
                        this.resultEvent.notify();
                    }
                    return;
                }
            }
        }
        this.dnsResult.set(false);
    }

    public class AdapterInfo {
        int netId;
        NetWorkState state = NetWorkState.AVAILABLE;

        AdapterInfo(int i) {
            this.netId = i;
        }
    }
}