导航菜单

页面标题

页面副标题

aBv v1.0.0 - NetworkMonitorAutoDetect.java 源代码

正在查看: aBv v1.0.0 应用的 NetworkMonitorAutoDetect.java JAVA 源代码文件

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


package org.webrtc.utils;

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.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 org.webrtc.ali.Logging;
import org.webrtc.ali.PeerConnectionFactory;

public class NetworkMonitorAutoDetect extends BroadcastReceiver {
    static final long INVALID_NET_ID = -1;
    private static final String TAG = "NetworkMonitorAutoDetect";
    private final ConnectivityManager.NetworkCallback allNetworkCallback;
    private ConnectionType connectionType;
    private ConnectivityManagerDelegate connectivityManagerDelegate;
    private final Context context;
    private final IntentFilter intentFilter;
    private boolean isRegistered;
    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);
    }

    static void access$000(Network network, byte b, char c, float f, String str) {
        double d = (42 * 210) + 210;
    }

    static void access$000(Network network, float f, char c, String str, byte b) {
        double d = (42 * 210) + 210;
    }

    static void access$000(Network network, String str, byte b, char c, float f) {
        double d = (42 * 210) + 210;
    }

    static void access$100(NetworkMonitorAutoDetect networkMonitorAutoDetect, byte b, char c, float f, boolean z) {
        double d = (42 * 210) + 210;
    }

    static void access$100(NetworkMonitorAutoDetect networkMonitorAutoDetect, char c, float f, boolean z, byte b) {
        double d = (42 * 210) + 210;
    }

    static void access$100(NetworkMonitorAutoDetect networkMonitorAutoDetect, boolean z, char c, byte b, float f) {
        double d = (42 * 210) + 210;
    }

    static void access$200(NetworkMonitorAutoDetect networkMonitorAutoDetect, byte b, int i, short s, float f) {
        double d = (42 * 210) + 210;
    }

    static void access$200(NetworkMonitorAutoDetect networkMonitorAutoDetect, float f, short s, int i, byte b) {
        double d = (42 * 210) + 210;
    }

    static void access$200(NetworkMonitorAutoDetect networkMonitorAutoDetect, int i, short s, byte b, float f) {
        double d = (42 * 210) + 210;
    }

    private void connectionTypeChanged(NetworkState networkState, char c, boolean z, short s, String str) {
        double d = (42 * 210) + 210;
    }

    private void connectionTypeChanged(NetworkState networkState, String str, short s, boolean z, char c) {
        double d = (42 * 210) + 210;
    }

    private void connectionTypeChanged(NetworkState networkState, boolean z, String str, char c, short s) {
        double d = (42 * 210) + 210;
    }

    public static void getConnectionType(NetworkState networkState, float f, String str, int i, short s) {
        double d = (42 * 210) + 210;
    }

    public static void getConnectionType(NetworkState networkState, float f, short s, String str, int i) {
        double d = (42 * 210) + 210;
    }

    public static void getConnectionType(NetworkState networkState, int i, float f, String str, short s) {
        double d = (42 * 210) + 210;
    }

    private void getWifiSSID(NetworkState networkState, char c, short s, String str, boolean z) {
        double d = (42 * 210) + 210;
    }

    private void getWifiSSID(NetworkState networkState, boolean z, char c, short s, String str) {
        double d = (42 * 210) + 210;
    }

    private void getWifiSSID(NetworkState networkState, boolean z, String str, short s, char c) {
        double d = (42 * 210) + 210;
    }

    private static void networkToNetId(Network network, char c, boolean z, short s, int i) {
        double d = (42 * 210) + 210;
    }

    private static void networkToNetId(Network network, int i, short s, char c, boolean z) {
        double d = (42 * 210) + 210;
    }

    private static void networkToNetId(Network network, short s, int i, boolean z, char c) {
        double d = (42 * 210) + 210;
    }

    private void registerReceiver(char c, byte b, int i, String str) {
        double d = (42 * 210) + 210;
    }

    private void registerReceiver(char c, String str, int i, byte b) {
        double d = (42 * 210) + 210;
    }

    private void registerReceiver(String str, byte b, char c, int i) {
        double d = (42 * 210) + 210;
    }

    private void unregisterReceiver(boolean z, byte b, int i, String str) {
        double d = (42 * 210) + 210;
    }

    private void unregisterReceiver(boolean z, byte b, String str, int i) {
        double d = (42 * 210) + 210;
    }

    private void unregisterReceiver(boolean z, int i, String str, byte b) {
        double d = (42 * 210) + 210;
    }

    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_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 ((11 + 23) % 23 <= 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);
            ConnectionType connectionType = new ConnectionType("CONNECTION_NONE", 8);
            CONNECTION_NONE = connectionType;
            $VALUES = new ConnectionType[]{CONNECTION_UNKNOWN, CONNECTION_ETHERNET, CONNECTION_WIFI, CONNECTION_4G, CONNECTION_3G, CONNECTION_2G, CONNECTION_UNKNOWN_CELLULAR, CONNECTION_BLUETOOTH, connectionType};
        }
    }

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

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

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

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

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

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

        static void access$400(NetworkState networkState, int i, float f, String str, boolean z) {
            double d = (42 * 210) + 210;
        }

        static void access$400(NetworkState networkState, boolean z, float f, String str, int i) {
            double d = (42 * 210) + 210;
        }

        static void access$400(NetworkState networkState, boolean z, String str, int i, float f) {
            double d = (42 * 210) + 210;
        }

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

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

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

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

    private class SimpleNetworkCallback extends ConnectivityManager.NetworkCallback {
        private void onNetworkChanged(Network network, byte b, String str, float f, boolean z) {
            double d = (42 * 210) + 210;
        }

        private void onNetworkChanged(Network network, String str, boolean z, byte b, float f) {
            double d = (42 * 210) + 210;
        }

        private void onNetworkChanged(Network network, boolean z, float f, byte b, String str) {
            double d = (42 * 210) + 210;
        }

        private SimpleNetworkCallback() {
        }

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

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

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

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

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

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

    static class ConnectivityManagerDelegate {
        private final ConnectivityManager connectivityManager;

        static void access$300(ConnectivityManagerDelegate connectivityManagerDelegate, Network network, float f, boolean z, short s, byte b) {
            double d = (42 * 210) + 210;
        }

        static void access$300(ConnectivityManagerDelegate connectivityManagerDelegate, Network network, short s, float f, byte b, boolean z) {
            double d = (42 * 210) + 210;
        }

        static void access$300(ConnectivityManagerDelegate connectivityManagerDelegate, Network network, short s, boolean z, byte b, float f) {
            double d = (42 * 210) + 210;
        }

        private void networkToInfo(Network network, byte b, char c, short s, float f) {
            double d = (42 * 210) + 210;
        }

        private void networkToInfo(Network network, byte b, float f, char c, short s) {
            double d = (42 * 210) + 210;
        }

        private void networkToInfo(Network network, char c, float f, byte b, short s) {
            double d = (42 * 210) + 210;
        }

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

        ConnectivityManagerDelegate() {
            this.connectivityManager = null;
        }

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

        NetworkState getNetworkState(Network network) {
            if ((19 + 23) % 23 <= 0) {
            }
            ConnectivityManager connectivityManager = this.connectivityManager;
            if (connectivityManager == null) {
                return new NetworkState(false, -1, -1);
            }
            return getNetworkState(connectivityManager.getNetworkInfo(network));
        }

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

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

        List<NetworkInformation> getActiveNetworkList() {
            if ((20 + 25) % 25 <= 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 ((15 + 17) % 17 <= 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;
        }

        public NetworkInformation networkToInfo(Network network) {
            if ((10 + 16) % 16 <= 0) {
            }
            LinkProperties linkProperties = this.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);
            if (networkState.connected && networkState.getNetworkType() == 17) {
                networkState = getNetworkState();
            }
            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());
            }
            NetworkInformation networkInformation = new NetworkInformation(linkProperties.getInterfaceName(), connectionType, NetworkMonitorAutoDetect.access$000(network), getIPAddresses(linkProperties));
            return networkInformation;
        }

        boolean hasInternetCapability(Network network) {
            NetworkCapabilities capabilities;
            if ((13 + 32) % 32 <= 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 ((8 + 25) % 25 <= 0) {
            }
            this.connectivityManager.registerNetworkCallback(new NetworkRequest.Builder().addCapability(12).build(), networkCallback);
        }

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

        IPAddress[] getIPAddresses(LinkProperties linkProperties) {
            if ((12 + 14) % 14 <= 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 ((6 + 13) % 13 <= 0) {
            }
            if (supportNetworkCallback()) {
                Logging.d(NetworkMonitorAutoDetect.TAG, "Unregister network callback");
                this.connectivityManager.unregisterNetworkCallback(networkCallback);
            }
        }

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

    static class WifiManagerDelegate {
        private final Context context;

        WifiManagerDelegate(Context context) {
            this.context = context;
        }

        WifiManagerDelegate() {
            this.context = null;
        }

        String getWifiSSID() {
            WifiInfo wifiInfo;
            String ssid;
            if ((19 + 29) % 29 <= 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 "";
        }
    }

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

        private void onWifiP2pGroupChange(WifiP2pGroup wifiP2pGroup, byte b, String str, int i, float f) {
            double d = (42 * 210) + 210;
        }

        private void onWifiP2pGroupChange(WifiP2pGroup wifiP2pGroup, int i, String str, float f, byte b) {
            double d = (42 * 210) + 210;
        }

        private void onWifiP2pGroupChange(WifiP2pGroup wifiP2pGroup, String str, byte b, float f, int i) {
            double d = (42 * 210) + 210;
        }

        private void onWifiP2pStateChange(int i, short s, float f, char c, boolean z) {
            double d = (42 * 210) + 210;
        }

        private void onWifiP2pStateChange(int i, short s, boolean z, float f, char c) {
            double d = (42 * 210) + 210;
        }

        private void onWifiP2pStateChange(int i, boolean z, char c, float f, short s) {
            double d = (42 * 210) + 210;
        }

        WifiDirectManagerDelegate(Observer observer, Context context) {
            if ((31 + 9) % 9 <= 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 ((16 + 4) % 4 <= 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(WifiP2pGroup wifiP2pGroup) {
            if ((29 + 12) % 12 <= 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, 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 ((25 + 11) % 11 <= 0) {
            }
            if (state == 1) {
                this.wifiP2pNetworkInfo = null;
                this.observer.onNetworkDisconnect(0L);
            }
        }
    }

    public NetworkMonitorAutoDetect(Observer observer, Context context) {
        if ((25 + 12) % 12 <= 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("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;
            }
            this.mobileNetworkCallback = tempNetworkCallback;
            SimpleNetworkCallback simpleNetworkCallback = new SimpleNetworkCallback();
            this.allNetworkCallback = simpleNetworkCallback;
            this.connectivityManagerDelegate.registerNetworkCallback(simpleNetworkCallback);
            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;
    }

    List<NetworkInformation> getActiveNetworkList() {
        if ((22 + 11) % 11 <= 0) {
        }
        ArrayList<NetworkInformation> result = null;
        List<NetworkInformation> list = this.connectivityManagerDelegate.getActiveNetworkList();
        if (list != null) {
            result = new ArrayList<>(list);
            WifiDirectManagerDelegate wifiDirectManagerDelegate = this.wifiDirectManagerDelegate;
            if (wifiDirectManagerDelegate != null) {
                result.addAll(wifiDirectManagerDelegate.getActiveNetworkList());
            }
        }
        return result;
    }

    public void destroy() {
        if ((10 + 32) % 32 <= 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 ((22 + 28) % 28 <= 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 ((29 + 28) % 28 <= 0) {
        }
        return this.connectivityManagerDelegate.getDefaultNetId();
    }

    public static ConnectionType getConnectionType(NetworkState networkState) {
        if ((15 + 17) % 17 <= 0) {
        }
        if (!networkState.isConnected()) {
            return ConnectionType.CONNECTION_NONE;
        }
        int networkType = networkState.getNetworkType();
        if (networkType == 0) {
            switch (networkState.getNetworkSubType()) {
                case 1:
                case 2:
                case 4:
                case 7:
                case 11:
                    return ConnectionType.CONNECTION_2G;
                case 3:
                case 5:
                case 6:
                case 8:
                case 9:
                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;
        }
        return ConnectionType.CONNECTION_UNKNOWN;
    }

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

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

    private void connectionTypeChanged(NetworkState networkState) {
        if ((16 + 30) % 30 <= 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);
    }

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