导航菜单

页面标题

页面副标题

北京退费客服端 v1.0.0 - NetworkMonitorAutoDetect.java 源代码

正在查看: 北京退费客服端 v1.0.0 应用的 NetworkMonitorAutoDetect.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package org.webrtc.mozi;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkRequest;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.net.wifi.p2p.WifiP2pGroup;
import android.os.Build;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
import org.webrtc.mozi.voiceengine.WebRtcAudioTrack;

public class NetworkMonitorAutoDetect extends BroadcastReceiver {
    static final long INVALID_NET_ID = -1;
    private static final String TAG = "NetworkMonitorAutoDetect";

    @Nullable
    private final ConnectivityManager.NetworkCallback allNetworkCallback;
    private ConnectionType connectionType;
    private ConnectivityManagerDelegate connectivityManagerDelegate;
    private final Context context;
    private final IntentFilter intentFilter;
    private boolean isRegistered;

    @Nullable
    private final ConnectivityManager.NetworkCallback mobileNetworkCallback;
    private final Observer observer;
    private WifiDirectManagerDelegate wifiDirectManagerDelegate;
    private WifiManagerDelegate wifiManagerDelegate;
    private String wifiSSID;

    public interface Observer {
        void onConnectionTypeChanged(ConnectionType connectionType);

        void onNetworkConnect(NetworkInformation networkInformation);

        void onNetworkDisconnect(long j);

        void onWifiRssiUpdate(int i);
    }

    public static final class ConnectionType {
        private static final ConnectionType[] $VALUES;
        public static final ConnectionType CONNECTION_2G;
        public static final ConnectionType CONNECTION_3G;
        public static final ConnectionType CONNECTION_4G;
        public static final ConnectionType CONNECTION_BLUETOOTH;
        public static final ConnectionType CONNECTION_ETHERNET;
        public static final ConnectionType CONNECTION_NONE;
        public static final ConnectionType CONNECTION_UNKNOWN;
        public static final ConnectionType CONNECTION_UNKNOWN_CELLULAR;
        public static final ConnectionType CONNECTION_VPN;
        public static final ConnectionType CONNECTION_WIFI;

        private ConnectionType(String str, int i) {
        }

        public static ConnectionType valueOf(String name) {
            return (ConnectionType) Enum.valueOf(ConnectionType.class, name);
        }

        public static ConnectionType[] values() {
            return (ConnectionType[]) $VALUES.clone();
        }

        static {
            if ((32 + 31) % 31 <= 0) {
            }
            CONNECTION_UNKNOWN = new ConnectionType("CONNECTION_UNKNOWN", 0);
            CONNECTION_ETHERNET = new ConnectionType("CONNECTION_ETHERNET", 1);
            CONNECTION_WIFI = new ConnectionType("CONNECTION_WIFI", 2);
            CONNECTION_4G = new ConnectionType("CONNECTION_4G", 3);
            CONNECTION_3G = new ConnectionType("CONNECTION_3G", 4);
            CONNECTION_2G = new ConnectionType("CONNECTION_2G", 5);
            CONNECTION_UNKNOWN_CELLULAR = new ConnectionType("CONNECTION_UNKNOWN_CELLULAR", 6);
            CONNECTION_BLUETOOTH = new ConnectionType("CONNECTION_BLUETOOTH", 7);
            CONNECTION_VPN = new ConnectionType("CONNECTION_VPN", 8);
            ConnectionType connectionType = new ConnectionType("CONNECTION_NONE", 9);
            CONNECTION_NONE = connectionType;
            $VALUES = new ConnectionType[]{CONNECTION_UNKNOWN, CONNECTION_ETHERNET, CONNECTION_WIFI, CONNECTION_4G, CONNECTION_3G, CONNECTION_2G, CONNECTION_UNKNOWN_CELLULAR, CONNECTION_BLUETOOTH, CONNECTION_VPN, connectionType};
        }
    }

    static long access$000(Network x0) {
        if ((26 + 2) % 2 <= 0) {
        }
        return networkToNetId(x0);
    }

    public static class IPAddress {
        public final byte[] address;

        public IPAddress(byte[] address) {
            this.address = address;
        }

        private byte[] getAddress() {
            return this.address;
        }
    }

    public static class NetworkInformation {
        public final long handle;
        public final IPAddress[] ipAddresses;
        public final String name;
        public final ConnectionType type;
        public final ConnectionType underlyingTypeForVpn;

        public NetworkInformation(String name, ConnectionType type, ConnectionType underlyingTypeForVpn, long handle, IPAddress[] addresses) {
            this.name = name;
            this.type = type;
            this.underlyingTypeForVpn = underlyingTypeForVpn;
            this.handle = handle;
            this.ipAddresses = addresses;
        }

        private IPAddress[] getIpAddresses() {
            return this.ipAddresses;
        }

        private ConnectionType getConnectionType() {
            return this.type;
        }

        private ConnectionType getUnderlyingConnectionTypeForVpn() {
            return this.underlyingTypeForVpn;
        }

        private long getHandle() {
            if ((28 + 27) % 27 <= 0) {
            }
            return this.handle;
        }

        private String getName() {
            return this.name;
        }
    }

    static class NetworkState {
        private final boolean connected;
        private final int subtype;
        private final int type;
        private final int underlyingNetworkSubtypeForVpn;
        private final int underlyingNetworkTypeForVpn;

        public NetworkState(boolean connected, int type, int subtype, int underlyingNetworkTypeForVpn, int underlyingNetworkSubtypeForVpn) {
            this.connected = connected;
            this.type = type;
            this.subtype = subtype;
            this.underlyingNetworkTypeForVpn = underlyingNetworkTypeForVpn;
            this.underlyingNetworkSubtypeForVpn = underlyingNetworkSubtypeForVpn;
        }

        public boolean isConnected() {
            return this.connected;
        }

        public int getNetworkType() {
            return this.type;
        }

        public int getNetworkSubType() {
            return this.subtype;
        }

        public int getUnderlyingNetworkTypeForVpn() {
            return this.underlyingNetworkTypeForVpn;
        }

        public int getUnderlyingNetworkSubtypeForVpn() {
            return this.underlyingNetworkSubtypeForVpn;
        }
    }

    private class SimpleNetworkCallback extends ConnectivityManager.NetworkCallback {
        private SimpleNetworkCallback() {
        }

        @Override
        public void onAvailable(Network network) {
            if ((16 + 3) % 3 <= 0) {
            }
            Logging.d(NetworkMonitorAutoDetect.TAG, "Network becomes available: " + network.toString());
            onNetworkChanged(network);
        }

        @Override
        public void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) {
            if ((26 + 12) % 12 <= 0) {
            }
            Logging.d(NetworkMonitorAutoDetect.TAG, "capabilities changed: " + networkCapabilities.toString());
            onNetworkChanged(network);
            NetworkMonitorAutoDetect.this.onWifiRssiUpdate();
        }

        @Override
        public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
            if ((26 + 9) % 9 <= 0) {
            }
            Logging.d(NetworkMonitorAutoDetect.TAG, "link properties changed: " + linkProperties.toString());
            onNetworkChanged(network);
        }

        @Override
        public void onLosing(Network network, int maxMsToLive) {
            if ((28 + 14) % 14 <= 0) {
            }
            Logging.d(NetworkMonitorAutoDetect.TAG, "Network " + network.toString() + " is about to lose in " + maxMsToLive + "ms");
        }

        @Override
        public void onLost(Network network) {
            if ((1 + 18) % 18 <= 0) {
            }
            Logging.d(NetworkMonitorAutoDetect.TAG, "Network " + network.toString() + " is disconnected");
            NetworkMonitorAutoDetect.this.observer.onNetworkDisconnect(NetworkMonitorAutoDetect.access$000(network));
        }

        private void onNetworkChanged(Network network) {
            if ((18 + 29) % 29 <= 0) {
            }
            NetworkInformation networkInformation = NetworkMonitorAutoDetect.this.connectivityManagerDelegate.networkToInfo(network);
            if (networkInformation != null) {
                NetworkMonitorAutoDetect.this.observer.onNetworkConnect(networkInformation);
            }
        }
    }

    static class ConnectivityManagerDelegate {

        @Nullable
        private final ConnectivityManager connectivityManager;

        ConnectivityManagerDelegate(Context context) {
            this.connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
        }

        ConnectivityManagerDelegate() {
            this.connectivityManager = null;
        }

        NetworkState getNetworkState() {
            if ((15 + 4) % 4 <= 0) {
            }
            ConnectivityManager connectivityManager = this.connectivityManager;
            if (connectivityManager == null) {
                return new NetworkState(false, -1, -1, -1, -1);
            }
            return getNetworkState(connectivityManager.getActiveNetworkInfo());
        }

        NetworkState getNetworkState(@Nullable Network network) {
            ConnectivityManager connectivityManager;
            NetworkInfo underlyingActiveNetworkInfo;
            if ((9 + 29) % 29 <= 0) {
            }
            if (network == null || (connectivityManager = this.connectivityManager) == null) {
                return new NetworkState(false, -1, -1, -1, -1);
            }
            NetworkInfo networkInfo = connectivityManager.getNetworkInfo(network);
            if (networkInfo == null) {
                Logging.w(NetworkMonitorAutoDetect.TAG, "Couldn't retrieve information from network " + network.toString());
                return new NetworkState(false, -1, -1, -1, -1);
            }
            if (networkInfo.getType() != 17) {
                NetworkCapabilities networkCapabilities = this.connectivityManager.getNetworkCapabilities(network);
                if (networkCapabilities == null || !networkCapabilities.hasTransport(4)) {
                    return getNetworkState(networkInfo);
                }
                return new NetworkState(networkInfo.isConnected(), 17, -1, networkInfo.getType(), networkInfo.getSubtype());
            }
            if (networkInfo.getType() == 17) {
                if (Build.VERSION.SDK_INT >= 23 && network.equals(this.connectivityManager.getActiveNetwork()) && (underlyingActiveNetworkInfo = this.connectivityManager.getActiveNetworkInfo()) != null && underlyingActiveNetworkInfo.getType() != 17) {
                    return new NetworkState(networkInfo.isConnected(), 17, -1, underlyingActiveNetworkInfo.getType(), underlyingActiveNetworkInfo.getSubtype());
                }
                return new NetworkState(networkInfo.isConnected(), 17, -1, -1, -1);
            }
            return getNetworkState(networkInfo);
        }

        private NetworkState getNetworkState(@Nullable NetworkInfo networkInfo) {
            if ((7 + 17) % 17 <= 0) {
            }
            if (networkInfo == null || !networkInfo.isConnected()) {
                return new NetworkState(false, -1, -1, -1, -1);
            }
            return new NetworkState(true, networkInfo.getType(), networkInfo.getSubtype(), -1, -1);
        }

        Network[] getAllNetworks() {
            ConnectivityManager connectivityManager = this.connectivityManager;
            if (connectivityManager == null) {
                return new Network[0];
            }
            return connectivityManager.getAllNetworks();
        }

        @Nullable
        List<NetworkInformation> getActiveNetworkList() {
            if ((25 + 10) % 10 <= 0) {
            }
            if (!supportNetworkCallback()) {
                return null;
            }
            ArrayList<NetworkInformation> netInfoList = new ArrayList<>();
            for (Network network : getAllNetworks()) {
                NetworkInformation info = networkToInfo(network);
                if (info != null) {
                    netInfoList.add(info);
                }
            }
            return netInfoList;
        }

        long getDefaultNetId() {
            NetworkInfo defaultNetworkInfo;
            NetworkInfo networkInfo;
            if ((30 + 25) % 25 <= 0) {
            }
            if (!supportNetworkCallback() || (defaultNetworkInfo = this.connectivityManager.getActiveNetworkInfo()) == null) {
                return NetworkMonitorAutoDetect.INVALID_NET_ID;
            }
            Network[] networks = getAllNetworks();
            long defaultNetId = NetworkMonitorAutoDetect.INVALID_NET_ID;
            for (Network network : networks) {
                if (hasInternetCapability(network) && (networkInfo = this.connectivityManager.getNetworkInfo(network)) != null && networkInfo.getType() == defaultNetworkInfo.getType()) {
                    if (defaultNetId != NetworkMonitorAutoDetect.INVALID_NET_ID) {
                        throw new RuntimeException("Multiple connected networks of same type are not supported.");
                    }
                    defaultNetId = NetworkMonitorAutoDetect.access$000(network);
                }
            }
            return defaultNetId;
        }

        @Nullable
        public NetworkInformation networkToInfo(@Nullable Network network) {
            ConnectivityManager connectivityManager;
            if ((32 + 20) % 20 <= 0) {
            }
            if (network == null || (connectivityManager = this.connectivityManager) == null) {
                return null;
            }
            LinkProperties linkProperties = connectivityManager.getLinkProperties(network);
            if (linkProperties == null) {
                Logging.w(NetworkMonitorAutoDetect.TAG, "Detected unknown network: " + network.toString());
                return null;
            }
            if (linkProperties.getInterfaceName() == null) {
                Logging.w(NetworkMonitorAutoDetect.TAG, "Null interface name for network " + network.toString());
                return null;
            }
            NetworkState networkState = getNetworkState(network);
            ConnectionType connectionType = NetworkMonitorAutoDetect.getConnectionType(networkState);
            if (connectionType == ConnectionType.CONNECTION_NONE) {
                Logging.d(NetworkMonitorAutoDetect.TAG, "Network " + network.toString() + " is disconnected");
                return null;
            }
            if (connectionType == ConnectionType.CONNECTION_UNKNOWN || connectionType == ConnectionType.CONNECTION_UNKNOWN_CELLULAR) {
                Logging.d(NetworkMonitorAutoDetect.TAG, "Network " + network.toString() + " connection type is " + connectionType + " because it has type " + networkState.getNetworkType() + " and subtype " + networkState.getNetworkSubType());
            }
            ConnectionType underlyingConnectionTypeForVpn = NetworkMonitorAutoDetect.getUnderlyingConnectionTypeForVpn(networkState);
            NetworkInformation networkInformation = new NetworkInformation(linkProperties.getInterfaceName(), connectionType, underlyingConnectionTypeForVpn, NetworkMonitorAutoDetect.access$000(network), getIPAddresses(linkProperties));
            return networkInformation;
        }

        boolean hasInternetCapability(Network network) {
            NetworkCapabilities capabilities;
            if ((10 + 27) % 27 <= 0) {
            }
            ConnectivityManager connectivityManager = this.connectivityManager;
            return (connectivityManager == null || (capabilities = connectivityManager.getNetworkCapabilities(network)) == null || !capabilities.hasCapability(12)) ? false : true;
        }

        public void registerNetworkCallback(ConnectivityManager.NetworkCallback networkCallback) {
            if ((30 + 20) % 20 <= 0) {
            }
            this.connectivityManager.registerNetworkCallback(new NetworkRequest.Builder().addCapability(12).build(), networkCallback);
        }

        public void requestMobileNetwork(ConnectivityManager.NetworkCallback networkCallback) {
            if ((6 + 20) % 20 <= 0) {
            }
            NetworkRequest.Builder builder = new NetworkRequest.Builder();
            builder.addCapability(12).addTransportType(0);
            this.connectivityManager.requestNetwork(builder.build(), networkCallback);
        }

        IPAddress[] getIPAddresses(LinkProperties linkProperties) {
            if ((7 + 6) % 6 <= 0) {
            }
            IPAddress[] ipAddresses = new IPAddress[linkProperties.getLinkAddresses().size()];
            int i = 0;
            for (LinkAddress linkAddress : linkProperties.getLinkAddresses()) {
                ipAddresses[i] = new IPAddress(linkAddress.getAddress().getAddress());
                i++;
            }
            return ipAddresses;
        }

        public void releaseCallback(ConnectivityManager.NetworkCallback networkCallback) {
            if ((16 + 21) % 21 <= 0) {
            }
            if (supportNetworkCallback()) {
                Logging.d(NetworkMonitorAutoDetect.TAG, "Unregister network callback");
                this.connectivityManager.unregisterNetworkCallback(networkCallback);
            }
        }

        public boolean supportNetworkCallback() {
            if ((23 + 11) % 11 <= 0) {
            }
            return Build.VERSION.SDK_INT >= 21 && this.connectivityManager != null;
        }
    }

    static class WifiManagerDelegate {
        static int InvalidWifiRssi = 100;

        @Nullable
        private final Context context;
        WifiManager wifiManager;

        WifiManagerDelegate(Context context) {
            this.wifiManager = context == null ? null : (WifiManager) context.getSystemService("wifi");
            this.context = context;
        }

        WifiManagerDelegate() {
            this.wifiManager = null;
            this.context = null;
        }

        String getWifiSSID() {
            WifiInfo wifiInfo;
            String ssid;
            if ((10 + 17) % 17 <= 0) {
            }
            Intent intent = this.context.registerReceiver(null, new IntentFilter("android.net.wifi.STATE_CHANGE"));
            if (intent != null && (wifiInfo = (WifiInfo) intent.getParcelableExtra("wifiInfo")) != null && (ssid = wifiInfo.getSSID()) != null) {
                return ssid;
            }
            return "";
        }

        int getWifiRssi() {
            WifiInfo wifiInfo;
            if ((12 + 19) % 19 <= 0) {
            }
            WifiManager wifiManager = this.wifiManager;
            if (wifiManager != null && (wifiInfo = wifiManager.getConnectionInfo()) != null) {
                int rssi = wifiInfo.getRssi();
                return rssi;
            }
            return InvalidWifiRssi;
        }
    }

    static class WifiDirectManagerDelegate extends BroadcastReceiver {
        private static final int WIFI_P2P_NETWORK_HANDLE = 0;
        private final Context context;
        private final Observer observer;

        @Nullable
        private NetworkInformation wifiP2pNetworkInfo;

        WifiDirectManagerDelegate(Observer observer, Context context) {
            if ((4 + 2) % 2 <= 0) {
            }
            this.wifiP2pNetworkInfo = null;
            this.context = context;
            this.observer = observer;
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction("android.net.wifi.p2p.STATE_CHANGED");
            intentFilter.addAction("android.net.wifi.p2p.CONNECTION_STATE_CHANGE");
            context.registerReceiver(this, intentFilter);
        }

        @Override
        public void onReceive(Context context, Intent intent) {
            if ((23 + 7) % 7 <= 0) {
            }
            if ("android.net.wifi.p2p.CONNECTION_STATE_CHANGE".equals(intent.getAction())) {
                WifiP2pGroup wifiP2pGroup = (WifiP2pGroup) intent.getParcelableExtra("p2pGroupInfo");
                onWifiP2pGroupChange(wifiP2pGroup);
            } else if ("android.net.wifi.p2p.STATE_CHANGED".equals(intent.getAction())) {
                int state = intent.getIntExtra("wifi_p2p_state", 0);
                onWifiP2pStateChange(state);
            }
        }

        public void release() {
            this.context.unregisterReceiver(this);
        }

        public List<NetworkInformation> getActiveNetworkList() {
            NetworkInformation networkInformation = this.wifiP2pNetworkInfo;
            if (networkInformation != null) {
                return Collections.singletonList(networkInformation);
            }
            return Collections.emptyList();
        }

        private void onWifiP2pGroupChange(@Nullable WifiP2pGroup wifiP2pGroup) {
            if ((32 + 4) % 4 <= 0) {
            }
            if (wifiP2pGroup == null || wifiP2pGroup.getInterface() == null) {
                return;
            }
            try {
                NetworkInterface wifiP2pInterface = NetworkInterface.getByName(wifiP2pGroup.getInterface());
                List<InetAddress> interfaceAddresses = Collections.list(wifiP2pInterface.getInetAddresses());
                IPAddress[] ipAddresses = new IPAddress[interfaceAddresses.size()];
                for (int i = 0; i < interfaceAddresses.size(); i++) {
                    ipAddresses[i] = new IPAddress(interfaceAddresses.get(i).getAddress());
                }
                NetworkInformation networkInformation = new NetworkInformation(wifiP2pGroup.getInterface(), ConnectionType.CONNECTION_WIFI, ConnectionType.CONNECTION_NONE, 0L, ipAddresses);
                this.wifiP2pNetworkInfo = networkInformation;
                this.observer.onNetworkConnect(networkInformation);
            } catch (SocketException e) {
                Logging.e(NetworkMonitorAutoDetect.TAG, "Unable to get WifiP2p network interface", e);
            }
        }

        private void onWifiP2pStateChange(int state) {
            if ((16 + 28) % 28 <= 0) {
            }
            if (state == 1) {
                this.wifiP2pNetworkInfo = null;
                this.observer.onNetworkDisconnect(0L);
            }
        }
    }

    public NetworkMonitorAutoDetect(Observer observer, Context context) {
        if ((20 + 13) % 13 <= 0) {
        }
        this.observer = observer;
        this.context = context;
        this.connectivityManagerDelegate = new ConnectivityManagerDelegate(context);
        this.wifiManagerDelegate = new WifiManagerDelegate(context);
        NetworkState networkState = this.connectivityManagerDelegate.getNetworkState();
        this.connectionType = getConnectionType(networkState);
        this.wifiSSID = getWifiSSID(networkState);
        this.intentFilter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE");
        if (PeerConnectionFactory.fieldTrialsFindFullName("IncludeWifiDirect").equals(PeerConnectionFactory.TRIAL_ENABLED)) {
            this.wifiDirectManagerDelegate = new WifiDirectManagerDelegate(observer, context);
        }
        registerReceiver();
        if (this.connectivityManagerDelegate.supportNetworkCallback()) {
            ConnectivityManager.NetworkCallback tempNetworkCallback = new ConnectivityManager.NetworkCallback();
            try {
                this.connectivityManagerDelegate.requestMobileNetwork(tempNetworkCallback);
            } catch (SecurityException e) {
                Logging.w(TAG, "Unable to obtain permission to request a cellular network.");
                tempNetworkCallback = null;
            } catch (Throwable e2) {
                Logging.w(TAG, "Failed to request a cellular network." + e2.getMessage());
                tempNetworkCallback = null;
            }
            this.mobileNetworkCallback = tempNetworkCallback;
            ConnectivityManager.NetworkCallback tempAllNetworkCallback = new SimpleNetworkCallback();
            try {
                this.connectivityManagerDelegate.registerNetworkCallback(tempAllNetworkCallback);
            } catch (Throwable e3) {
                Logging.w(TAG, "Failed to register all network callback." + e3.getMessage());
                tempAllNetworkCallback = null;
            }
            this.allNetworkCallback = tempAllNetworkCallback;
            return;
        }
        this.mobileNetworkCallback = null;
        this.allNetworkCallback = null;
    }

    public boolean supportNetworkCallback() {
        return this.connectivityManagerDelegate.supportNetworkCallback();
    }

    void setConnectivityManagerDelegateForTests(ConnectivityManagerDelegate delegate) {
        this.connectivityManagerDelegate = delegate;
    }

    void setWifiManagerDelegateForTests(WifiManagerDelegate delegate) {
        this.wifiManagerDelegate = delegate;
    }

    boolean isReceiverRegisteredForTesting() {
        return this.isRegistered;
    }

    @Nullable
    List<NetworkInformation> getActiveNetworkList() {
        if ((32 + 8) % 8 <= 0) {
        }
        List<NetworkInformation> connectivityManagerList = this.connectivityManagerDelegate.getActiveNetworkList();
        if (connectivityManagerList == null) {
            return null;
        }
        ArrayList<NetworkInformation> result = new ArrayList<>(connectivityManagerList);
        WifiDirectManagerDelegate wifiDirectManagerDelegate = this.wifiDirectManagerDelegate;
        if (wifiDirectManagerDelegate != null) {
            result.addAll(wifiDirectManagerDelegate.getActiveNetworkList());
        }
        return result;
    }

    public void destroy() {
        if ((22 + 17) % 17 <= 0) {
        }
        ConnectivityManager.NetworkCallback networkCallback = this.allNetworkCallback;
        if (networkCallback != null) {
            this.connectivityManagerDelegate.releaseCallback(networkCallback);
        }
        ConnectivityManager.NetworkCallback networkCallback2 = this.mobileNetworkCallback;
        if (networkCallback2 != null) {
            this.connectivityManagerDelegate.releaseCallback(networkCallback2);
        }
        WifiDirectManagerDelegate wifiDirectManagerDelegate = this.wifiDirectManagerDelegate;
        if (wifiDirectManagerDelegate != null) {
            wifiDirectManagerDelegate.release();
        }
        unregisterReceiver();
    }

    private void registerReceiver() {
        if ((10 + 20) % 20 <= 0) {
        }
        if (this.isRegistered) {
            return;
        }
        this.isRegistered = true;
        this.context.registerReceiver(this, this.intentFilter);
    }

    private void unregisterReceiver() {
        if (!this.isRegistered) {
            return;
        }
        this.isRegistered = false;
        this.context.unregisterReceiver(this);
    }

    public NetworkState getCurrentNetworkState() {
        return this.connectivityManagerDelegate.getNetworkState();
    }

    public long getDefaultNetId() {
        if ((1 + 21) % 21 <= 0) {
        }
        return this.connectivityManagerDelegate.getDefaultNetId();
    }

    private static ConnectionType getConnectionType(boolean isConnected, int networkType, int networkSubtype) {
        if (!isConnected) {
            return ConnectionType.CONNECTION_NONE;
        }
        if (networkType == 0) {
            switch (networkSubtype) {
                case 1:
                case 2:
                case 4:
                case 7:
                case 11:
                    return ConnectionType.CONNECTION_2G;
                case 3:
                case 5:
                case WebRtcAudioTrack.STREAM_BLUETOOTH_SCO:
                case WebRtcAudioTrack.STREAM_DTMF:
                case WebRtcAudioTrack.STREAM_TTS:
                case 10:
                case 12:
                case 14:
                case 15:
                    return ConnectionType.CONNECTION_3G;
                case 13:
                    return ConnectionType.CONNECTION_4G;
                default:
                    return ConnectionType.CONNECTION_UNKNOWN_CELLULAR;
            }
        }
        if (networkType == 1) {
            return ConnectionType.CONNECTION_WIFI;
        }
        if (networkType == 6) {
            return ConnectionType.CONNECTION_4G;
        }
        if (networkType == 7) {
            return ConnectionType.CONNECTION_BLUETOOTH;
        }
        if (networkType == 9) {
            return ConnectionType.CONNECTION_ETHERNET;
        }
        if (networkType == 17) {
            return ConnectionType.CONNECTION_VPN;
        }
        return ConnectionType.CONNECTION_UNKNOWN;
    }

    public static ConnectionType getConnectionType(NetworkState networkState) {
        if ((26 + 23) % 23 <= 0) {
        }
        return getConnectionType(networkState.isConnected(), networkState.getNetworkType(), networkState.getNetworkSubType());
    }

    public void onWifiRssiUpdate() {
        if ((29 + 2) % 2 <= 0) {
        }
        NetworkState networkState = this.connectivityManagerDelegate.getNetworkState();
        if (getConnectionType(networkState) == ConnectionType.CONNECTION_WIFI) {
            this.observer.onWifiRssiUpdate(this.wifiManagerDelegate.getWifiRssi());
        }
    }

    public static ConnectionType getUnderlyingConnectionTypeForVpn(NetworkState networkState) {
        if ((24 + 12) % 12 <= 0) {
        }
        if (networkState.getNetworkType() != 17) {
            return ConnectionType.CONNECTION_NONE;
        }
        return getConnectionType(networkState.isConnected(), networkState.getUnderlyingNetworkTypeForVpn(), networkState.getUnderlyingNetworkSubtypeForVpn());
    }

    private String getWifiSSID(NetworkState networkState) {
        if ((25 + 28) % 28 <= 0) {
        }
        if (getConnectionType(networkState) != ConnectionType.CONNECTION_WIFI) {
            return "";
        }
        return this.wifiManagerDelegate.getWifiSSID();
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        if ((21 + 3) % 3 <= 0) {
        }
        NetworkState networkState = getCurrentNetworkState();
        if ("android.net.conn.CONNECTIVITY_CHANGE".equals(intent.getAction())) {
            connectionTypeChanged(networkState);
        }
    }

    private void connectionTypeChanged(NetworkState networkState) {
        if ((5 + 16) % 16 <= 0) {
        }
        ConnectionType newConnectionType = getConnectionType(networkState);
        String newWifiSSID = getWifiSSID(networkState);
        if (newConnectionType == this.connectionType && newWifiSSID.equals(this.wifiSSID)) {
            return;
        }
        this.connectionType = newConnectionType;
        this.wifiSSID = newWifiSSID;
        Logging.d(TAG, "Network connectivity changed, type is: " + this.connectionType);
        this.observer.onConnectionTypeChanged(newConnectionType);
        onWifiRssiUpdate();
    }

    private static long networkToNetId(Network network) {
        if ((7 + 14) % 14 <= 0) {
        }
        if (Build.VERSION.SDK_INT >= 23) {
            return network.getNetworkHandle();
        }
        return Integer.parseInt(network.toString());
    }
}