Search in sources :

Example 1 with IpConfiguration

use of android.net.IpConfiguration in project android_frameworks_base by DirtyUnicorns.

the class IpConfigStore method readIpAndProxyConfigurations.

public SparseArray<IpConfiguration> readIpAndProxyConfigurations(String filePath) {
    SparseArray<IpConfiguration> networks = new SparseArray<IpConfiguration>();
    DataInputStream in = null;
    try {
        in = new DataInputStream(new BufferedInputStream(new FileInputStream(filePath)));
        int version = in.readInt();
        if (version != 2 && version != 1) {
            loge("Bad version on IP configuration file, ignore read");
            return null;
        }
        while (true) {
            int id = -1;
            // Default is DHCP with no proxy
            IpAssignment ipAssignment = IpAssignment.DHCP;
            ProxySettings proxySettings = ProxySettings.NONE;
            StaticIpConfiguration staticIpConfiguration = new StaticIpConfiguration();
            String proxyHost = null;
            String pacFileUrl = null;
            int proxyPort = -1;
            String exclusionList = null;
            String key;
            do {
                key = in.readUTF();
                try {
                    if (key.equals(ID_KEY)) {
                        id = in.readInt();
                    } else if (key.equals(IP_ASSIGNMENT_KEY)) {
                        ipAssignment = IpAssignment.valueOf(in.readUTF());
                    } else if (key.equals(LINK_ADDRESS_KEY)) {
                        LinkAddress linkAddr = new LinkAddress(NetworkUtils.numericToInetAddress(in.readUTF()), in.readInt());
                        if (linkAddr.getAddress() instanceof Inet4Address && staticIpConfiguration.ipAddress == null) {
                            staticIpConfiguration.ipAddress = linkAddr;
                        } else {
                            loge("Non-IPv4 or duplicate address: " + linkAddr);
                        }
                    } else if (key.equals(GATEWAY_KEY)) {
                        LinkAddress dest = null;
                        InetAddress gateway = null;
                        if (version == 1) {
                            // only supported default gateways - leave the dest/prefix empty
                            gateway = NetworkUtils.numericToInetAddress(in.readUTF());
                            if (staticIpConfiguration.gateway == null) {
                                staticIpConfiguration.gateway = gateway;
                            } else {
                                loge("Duplicate gateway: " + gateway.getHostAddress());
                            }
                        } else {
                            if (in.readInt() == 1) {
                                dest = new LinkAddress(NetworkUtils.numericToInetAddress(in.readUTF()), in.readInt());
                            }
                            if (in.readInt() == 1) {
                                gateway = NetworkUtils.numericToInetAddress(in.readUTF());
                            }
                            RouteInfo route = new RouteInfo(dest, gateway);
                            if (route.isIPv4Default() && staticIpConfiguration.gateway == null) {
                                staticIpConfiguration.gateway = gateway;
                            } else {
                                loge("Non-IPv4 default or duplicate route: " + route);
                            }
                        }
                    } else if (key.equals(DNS_KEY)) {
                        staticIpConfiguration.dnsServers.add(NetworkUtils.numericToInetAddress(in.readUTF()));
                    } else if (key.equals(PROXY_SETTINGS_KEY)) {
                        proxySettings = ProxySettings.valueOf(in.readUTF());
                    } else if (key.equals(PROXY_HOST_KEY)) {
                        proxyHost = in.readUTF();
                    } else if (key.equals(PROXY_PORT_KEY)) {
                        proxyPort = in.readInt();
                    } else if (key.equals(PROXY_PAC_FILE)) {
                        pacFileUrl = in.readUTF();
                    } else if (key.equals(EXCLUSION_LIST_KEY)) {
                        exclusionList = in.readUTF();
                    } else if (key.equals(EOS)) {
                        break;
                    } else {
                        loge("Ignore unknown key " + key + "while reading");
                    }
                } catch (IllegalArgumentException e) {
                    loge("Ignore invalid address while reading" + e);
                }
            } while (true);
            if (id != -1) {
                IpConfiguration config = new IpConfiguration();
                networks.put(id, config);
                switch(ipAssignment) {
                    case STATIC:
                        config.staticIpConfiguration = staticIpConfiguration;
                        config.ipAssignment = ipAssignment;
                        break;
                    case DHCP:
                        config.ipAssignment = ipAssignment;
                        break;
                    case UNASSIGNED:
                        loge("BUG: Found UNASSIGNED IP on file, use DHCP");
                        config.ipAssignment = IpAssignment.DHCP;
                        break;
                    default:
                        loge("Ignore invalid ip assignment while reading.");
                        config.ipAssignment = IpAssignment.UNASSIGNED;
                        break;
                }
                switch(proxySettings) {
                    case STATIC:
                        ProxyInfo proxyInfo = new ProxyInfo(proxyHost, proxyPort, exclusionList);
                        config.proxySettings = proxySettings;
                        config.httpProxy = proxyInfo;
                        break;
                    case PAC:
                        ProxyInfo proxyPacProperties = new ProxyInfo(pacFileUrl);
                        config.proxySettings = proxySettings;
                        config.httpProxy = proxyPacProperties;
                        break;
                    case NONE:
                        config.proxySettings = proxySettings;
                        break;
                    case UNASSIGNED:
                        loge("BUG: Found UNASSIGNED proxy on file, use NONE");
                        config.proxySettings = ProxySettings.NONE;
                        break;
                    default:
                        loge("Ignore invalid proxy settings while reading");
                        config.proxySettings = ProxySettings.UNASSIGNED;
                        break;
                }
            } else {
                if (DBG)
                    log("Missing id while parsing configuration");
            }
        }
    } catch (EOFException ignore) {
    } catch (IOException e) {
        loge("Error parsing configuration: " + e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (Exception e) {
            }
        }
    }
    return networks;
}
Also used : LinkAddress(android.net.LinkAddress) Inet4Address(java.net.Inet4Address) IpConfiguration(android.net.IpConfiguration) StaticIpConfiguration(android.net.StaticIpConfiguration) IpAssignment(android.net.IpConfiguration.IpAssignment) ProxySettings(android.net.IpConfiguration.ProxySettings) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) EOFException(java.io.EOFException) ProxyInfo(android.net.ProxyInfo) SparseArray(android.util.SparseArray) BufferedInputStream(java.io.BufferedInputStream) StaticIpConfiguration(android.net.StaticIpConfiguration) EOFException(java.io.EOFException) RouteInfo(android.net.RouteInfo) InetAddress(java.net.InetAddress)

Example 2 with IpConfiguration

use of android.net.IpConfiguration in project android_frameworks_base by AOSPA.

the class IpConfigStore method readIpAndProxyConfigurations.

public SparseArray<IpConfiguration> readIpAndProxyConfigurations(String filePath) {
    SparseArray<IpConfiguration> networks = new SparseArray<IpConfiguration>();
    DataInputStream in = null;
    try {
        in = new DataInputStream(new BufferedInputStream(new FileInputStream(filePath)));
        int version = in.readInt();
        if (version != 2 && version != 1) {
            loge("Bad version on IP configuration file, ignore read");
            return null;
        }
        while (true) {
            int id = -1;
            // Default is DHCP with no proxy
            IpAssignment ipAssignment = IpAssignment.DHCP;
            ProxySettings proxySettings = ProxySettings.NONE;
            StaticIpConfiguration staticIpConfiguration = new StaticIpConfiguration();
            String proxyHost = null;
            String pacFileUrl = null;
            int proxyPort = -1;
            String exclusionList = null;
            String key;
            do {
                key = in.readUTF();
                try {
                    if (key.equals(ID_KEY)) {
                        id = in.readInt();
                    } else if (key.equals(IP_ASSIGNMENT_KEY)) {
                        ipAssignment = IpAssignment.valueOf(in.readUTF());
                    } else if (key.equals(LINK_ADDRESS_KEY)) {
                        LinkAddress linkAddr = new LinkAddress(NetworkUtils.numericToInetAddress(in.readUTF()), in.readInt());
                        if (linkAddr.getAddress() instanceof Inet4Address && staticIpConfiguration.ipAddress == null) {
                            staticIpConfiguration.ipAddress = linkAddr;
                        } else {
                            loge("Non-IPv4 or duplicate address: " + linkAddr);
                        }
                    } else if (key.equals(GATEWAY_KEY)) {
                        LinkAddress dest = null;
                        InetAddress gateway = null;
                        if (version == 1) {
                            // only supported default gateways - leave the dest/prefix empty
                            gateway = NetworkUtils.numericToInetAddress(in.readUTF());
                            if (staticIpConfiguration.gateway == null) {
                                staticIpConfiguration.gateway = gateway;
                            } else {
                                loge("Duplicate gateway: " + gateway.getHostAddress());
                            }
                        } else {
                            if (in.readInt() == 1) {
                                dest = new LinkAddress(NetworkUtils.numericToInetAddress(in.readUTF()), in.readInt());
                            }
                            if (in.readInt() == 1) {
                                gateway = NetworkUtils.numericToInetAddress(in.readUTF());
                            }
                            RouteInfo route = new RouteInfo(dest, gateway);
                            if (route.isIPv4Default() && staticIpConfiguration.gateway == null) {
                                staticIpConfiguration.gateway = gateway;
                            } else {
                                loge("Non-IPv4 default or duplicate route: " + route);
                            }
                        }
                    } else if (key.equals(DNS_KEY)) {
                        staticIpConfiguration.dnsServers.add(NetworkUtils.numericToInetAddress(in.readUTF()));
                    } else if (key.equals(PROXY_SETTINGS_KEY)) {
                        proxySettings = ProxySettings.valueOf(in.readUTF());
                    } else if (key.equals(PROXY_HOST_KEY)) {
                        proxyHost = in.readUTF();
                    } else if (key.equals(PROXY_PORT_KEY)) {
                        proxyPort = in.readInt();
                    } else if (key.equals(PROXY_PAC_FILE)) {
                        pacFileUrl = in.readUTF();
                    } else if (key.equals(EXCLUSION_LIST_KEY)) {
                        exclusionList = in.readUTF();
                    } else if (key.equals(EOS)) {
                        break;
                    } else {
                        loge("Ignore unknown key " + key + "while reading");
                    }
                } catch (IllegalArgumentException e) {
                    loge("Ignore invalid address while reading" + e);
                }
            } while (true);
            if (id != -1) {
                IpConfiguration config = new IpConfiguration();
                networks.put(id, config);
                switch(ipAssignment) {
                    case STATIC:
                        config.staticIpConfiguration = staticIpConfiguration;
                        config.ipAssignment = ipAssignment;
                        break;
                    case DHCP:
                        config.ipAssignment = ipAssignment;
                        break;
                    case UNASSIGNED:
                        loge("BUG: Found UNASSIGNED IP on file, use DHCP");
                        config.ipAssignment = IpAssignment.DHCP;
                        break;
                    default:
                        loge("Ignore invalid ip assignment while reading.");
                        config.ipAssignment = IpAssignment.UNASSIGNED;
                        break;
                }
                switch(proxySettings) {
                    case STATIC:
                        ProxyInfo proxyInfo = new ProxyInfo(proxyHost, proxyPort, exclusionList);
                        config.proxySettings = proxySettings;
                        config.httpProxy = proxyInfo;
                        break;
                    case PAC:
                        ProxyInfo proxyPacProperties = new ProxyInfo(pacFileUrl);
                        config.proxySettings = proxySettings;
                        config.httpProxy = proxyPacProperties;
                        break;
                    case NONE:
                        config.proxySettings = proxySettings;
                        break;
                    case UNASSIGNED:
                        loge("BUG: Found UNASSIGNED proxy on file, use NONE");
                        config.proxySettings = ProxySettings.NONE;
                        break;
                    default:
                        loge("Ignore invalid proxy settings while reading");
                        config.proxySettings = ProxySettings.UNASSIGNED;
                        break;
                }
            } else {
                if (DBG)
                    log("Missing id while parsing configuration");
            }
        }
    } catch (EOFException ignore) {
    } catch (IOException e) {
        loge("Error parsing configuration: " + e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (Exception e) {
            }
        }
    }
    return networks;
}
Also used : LinkAddress(android.net.LinkAddress) Inet4Address(java.net.Inet4Address) IpConfiguration(android.net.IpConfiguration) StaticIpConfiguration(android.net.StaticIpConfiguration) IpAssignment(android.net.IpConfiguration.IpAssignment) ProxySettings(android.net.IpConfiguration.ProxySettings) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) EOFException(java.io.EOFException) ProxyInfo(android.net.ProxyInfo) SparseArray(android.util.SparseArray) BufferedInputStream(java.io.BufferedInputStream) StaticIpConfiguration(android.net.StaticIpConfiguration) EOFException(java.io.EOFException) RouteInfo(android.net.RouteInfo) InetAddress(java.net.InetAddress)

Example 3 with IpConfiguration

use of android.net.IpConfiguration in project platform_frameworks_base by android.

the class IpConfigStore method readIpAndProxyConfigurations.

public static SparseArray<IpConfiguration> readIpAndProxyConfigurations(InputStream inputStream) {
    SparseArray<IpConfiguration> networks = new SparseArray<IpConfiguration>();
    DataInputStream in = null;
    try {
        in = new DataInputStream(inputStream);
        int version = in.readInt();
        if (version != 2 && version != 1) {
            loge("Bad version on IP configuration file, ignore read");
            return null;
        }
        while (true) {
            int id = -1;
            // Default is DHCP with no proxy
            IpAssignment ipAssignment = IpAssignment.DHCP;
            ProxySettings proxySettings = ProxySettings.NONE;
            StaticIpConfiguration staticIpConfiguration = new StaticIpConfiguration();
            String proxyHost = null;
            String pacFileUrl = null;
            int proxyPort = -1;
            String exclusionList = null;
            String key;
            do {
                key = in.readUTF();
                try {
                    if (key.equals(ID_KEY)) {
                        id = in.readInt();
                    } else if (key.equals(IP_ASSIGNMENT_KEY)) {
                        ipAssignment = IpAssignment.valueOf(in.readUTF());
                    } else if (key.equals(LINK_ADDRESS_KEY)) {
                        LinkAddress linkAddr = new LinkAddress(NetworkUtils.numericToInetAddress(in.readUTF()), in.readInt());
                        if (linkAddr.getAddress() instanceof Inet4Address && staticIpConfiguration.ipAddress == null) {
                            staticIpConfiguration.ipAddress = linkAddr;
                        } else {
                            loge("Non-IPv4 or duplicate address: " + linkAddr);
                        }
                    } else if (key.equals(GATEWAY_KEY)) {
                        LinkAddress dest = null;
                        InetAddress gateway = null;
                        if (version == 1) {
                            // only supported default gateways - leave the dest/prefix empty
                            gateway = NetworkUtils.numericToInetAddress(in.readUTF());
                            if (staticIpConfiguration.gateway == null) {
                                staticIpConfiguration.gateway = gateway;
                            } else {
                                loge("Duplicate gateway: " + gateway.getHostAddress());
                            }
                        } else {
                            if (in.readInt() == 1) {
                                dest = new LinkAddress(NetworkUtils.numericToInetAddress(in.readUTF()), in.readInt());
                            }
                            if (in.readInt() == 1) {
                                gateway = NetworkUtils.numericToInetAddress(in.readUTF());
                            }
                            RouteInfo route = new RouteInfo(dest, gateway);
                            if (route.isIPv4Default() && staticIpConfiguration.gateway == null) {
                                staticIpConfiguration.gateway = gateway;
                            } else {
                                loge("Non-IPv4 default or duplicate route: " + route);
                            }
                        }
                    } else if (key.equals(DNS_KEY)) {
                        staticIpConfiguration.dnsServers.add(NetworkUtils.numericToInetAddress(in.readUTF()));
                    } else if (key.equals(PROXY_SETTINGS_KEY)) {
                        proxySettings = ProxySettings.valueOf(in.readUTF());
                    } else if (key.equals(PROXY_HOST_KEY)) {
                        proxyHost = in.readUTF();
                    } else if (key.equals(PROXY_PORT_KEY)) {
                        proxyPort = in.readInt();
                    } else if (key.equals(PROXY_PAC_FILE)) {
                        pacFileUrl = in.readUTF();
                    } else if (key.equals(EXCLUSION_LIST_KEY)) {
                        exclusionList = in.readUTF();
                    } else if (key.equals(EOS)) {
                        break;
                    } else {
                        loge("Ignore unknown key " + key + "while reading");
                    }
                } catch (IllegalArgumentException e) {
                    loge("Ignore invalid address while reading" + e);
                }
            } while (true);
            if (id != -1) {
                IpConfiguration config = new IpConfiguration();
                networks.put(id, config);
                switch(ipAssignment) {
                    case STATIC:
                        config.staticIpConfiguration = staticIpConfiguration;
                        config.ipAssignment = ipAssignment;
                        break;
                    case DHCP:
                        config.ipAssignment = ipAssignment;
                        break;
                    case UNASSIGNED:
                        loge("BUG: Found UNASSIGNED IP on file, use DHCP");
                        config.ipAssignment = IpAssignment.DHCP;
                        break;
                    default:
                        loge("Ignore invalid ip assignment while reading.");
                        config.ipAssignment = IpAssignment.UNASSIGNED;
                        break;
                }
                switch(proxySettings) {
                    case STATIC:
                        ProxyInfo proxyInfo = new ProxyInfo(proxyHost, proxyPort, exclusionList);
                        config.proxySettings = proxySettings;
                        config.httpProxy = proxyInfo;
                        break;
                    case PAC:
                        ProxyInfo proxyPacProperties = new ProxyInfo(pacFileUrl);
                        config.proxySettings = proxySettings;
                        config.httpProxy = proxyPacProperties;
                        break;
                    case NONE:
                        config.proxySettings = proxySettings;
                        break;
                    case UNASSIGNED:
                        loge("BUG: Found UNASSIGNED proxy on file, use NONE");
                        config.proxySettings = ProxySettings.NONE;
                        break;
                    default:
                        loge("Ignore invalid proxy settings while reading");
                        config.proxySettings = ProxySettings.UNASSIGNED;
                        break;
                }
            } else {
                if (DBG)
                    log("Missing id while parsing configuration");
            }
        }
    } catch (EOFException ignore) {
    } catch (IOException e) {
        loge("Error parsing configuration: " + e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (Exception e) {
            }
        }
    }
    return networks;
}
Also used : LinkAddress(android.net.LinkAddress) Inet4Address(java.net.Inet4Address) IpConfiguration(android.net.IpConfiguration) StaticIpConfiguration(android.net.StaticIpConfiguration) IpAssignment(android.net.IpConfiguration.IpAssignment) ProxySettings(android.net.IpConfiguration.ProxySettings) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) IOException(java.io.IOException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) ProxyInfo(android.net.ProxyInfo) SparseArray(android.util.SparseArray) StaticIpConfiguration(android.net.StaticIpConfiguration) EOFException(java.io.EOFException) RouteInfo(android.net.RouteInfo) InetAddress(java.net.InetAddress)

Example 4 with IpConfiguration

use of android.net.IpConfiguration in project android_frameworks_base by ResurrectionRemix.

the class IpConfigStore method readIpAndProxyConfigurations.

public SparseArray<IpConfiguration> readIpAndProxyConfigurations(String filePath) {
    SparseArray<IpConfiguration> networks = new SparseArray<IpConfiguration>();
    DataInputStream in = null;
    try {
        in = new DataInputStream(new BufferedInputStream(new FileInputStream(filePath)));
        int version = in.readInt();
        if (version != 2 && version != 1) {
            loge("Bad version on IP configuration file, ignore read");
            return null;
        }
        while (true) {
            int id = -1;
            // Default is DHCP with no proxy
            IpAssignment ipAssignment = IpAssignment.DHCP;
            ProxySettings proxySettings = ProxySettings.NONE;
            StaticIpConfiguration staticIpConfiguration = new StaticIpConfiguration();
            String proxyHost = null;
            String pacFileUrl = null;
            int proxyPort = -1;
            String exclusionList = null;
            String key;
            do {
                key = in.readUTF();
                try {
                    if (key.equals(ID_KEY)) {
                        id = in.readInt();
                    } else if (key.equals(IP_ASSIGNMENT_KEY)) {
                        ipAssignment = IpAssignment.valueOf(in.readUTF());
                    } else if (key.equals(LINK_ADDRESS_KEY)) {
                        LinkAddress linkAddr = new LinkAddress(NetworkUtils.numericToInetAddress(in.readUTF()), in.readInt());
                        if (linkAddr.getAddress() instanceof Inet4Address && staticIpConfiguration.ipAddress == null) {
                            staticIpConfiguration.ipAddress = linkAddr;
                        } else {
                            loge("Non-IPv4 or duplicate address: " + linkAddr);
                        }
                    } else if (key.equals(GATEWAY_KEY)) {
                        LinkAddress dest = null;
                        InetAddress gateway = null;
                        if (version == 1) {
                            // only supported default gateways - leave the dest/prefix empty
                            gateway = NetworkUtils.numericToInetAddress(in.readUTF());
                            if (staticIpConfiguration.gateway == null) {
                                staticIpConfiguration.gateway = gateway;
                            } else {
                                loge("Duplicate gateway: " + gateway.getHostAddress());
                            }
                        } else {
                            if (in.readInt() == 1) {
                                dest = new LinkAddress(NetworkUtils.numericToInetAddress(in.readUTF()), in.readInt());
                            }
                            if (in.readInt() == 1) {
                                gateway = NetworkUtils.numericToInetAddress(in.readUTF());
                            }
                            RouteInfo route = new RouteInfo(dest, gateway);
                            if (route.isIPv4Default() && staticIpConfiguration.gateway == null) {
                                staticIpConfiguration.gateway = gateway;
                            } else {
                                loge("Non-IPv4 default or duplicate route: " + route);
                            }
                        }
                    } else if (key.equals(DNS_KEY)) {
                        staticIpConfiguration.dnsServers.add(NetworkUtils.numericToInetAddress(in.readUTF()));
                    } else if (key.equals(PROXY_SETTINGS_KEY)) {
                        proxySettings = ProxySettings.valueOf(in.readUTF());
                    } else if (key.equals(PROXY_HOST_KEY)) {
                        proxyHost = in.readUTF();
                    } else if (key.equals(PROXY_PORT_KEY)) {
                        proxyPort = in.readInt();
                    } else if (key.equals(PROXY_PAC_FILE)) {
                        pacFileUrl = in.readUTF();
                    } else if (key.equals(EXCLUSION_LIST_KEY)) {
                        exclusionList = in.readUTF();
                    } else if (key.equals(EOS)) {
                        break;
                    } else {
                        loge("Ignore unknown key " + key + "while reading");
                    }
                } catch (IllegalArgumentException e) {
                    loge("Ignore invalid address while reading" + e);
                }
            } while (true);
            if (id != -1) {
                IpConfiguration config = new IpConfiguration();
                networks.put(id, config);
                switch(ipAssignment) {
                    case STATIC:
                        config.staticIpConfiguration = staticIpConfiguration;
                        config.ipAssignment = ipAssignment;
                        break;
                    case DHCP:
                        config.ipAssignment = ipAssignment;
                        break;
                    case UNASSIGNED:
                        loge("BUG: Found UNASSIGNED IP on file, use DHCP");
                        config.ipAssignment = IpAssignment.DHCP;
                        break;
                    default:
                        loge("Ignore invalid ip assignment while reading.");
                        config.ipAssignment = IpAssignment.UNASSIGNED;
                        break;
                }
                switch(proxySettings) {
                    case STATIC:
                        ProxyInfo proxyInfo = new ProxyInfo(proxyHost, proxyPort, exclusionList);
                        config.proxySettings = proxySettings;
                        config.httpProxy = proxyInfo;
                        break;
                    case PAC:
                        ProxyInfo proxyPacProperties = new ProxyInfo(pacFileUrl);
                        config.proxySettings = proxySettings;
                        config.httpProxy = proxyPacProperties;
                        break;
                    case NONE:
                        config.proxySettings = proxySettings;
                        break;
                    case UNASSIGNED:
                        loge("BUG: Found UNASSIGNED proxy on file, use NONE");
                        config.proxySettings = ProxySettings.NONE;
                        break;
                    default:
                        loge("Ignore invalid proxy settings while reading");
                        config.proxySettings = ProxySettings.UNASSIGNED;
                        break;
                }
            } else {
                if (DBG)
                    log("Missing id while parsing configuration");
            }
        }
    } catch (EOFException ignore) {
    } catch (IOException e) {
        loge("Error parsing configuration: " + e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (Exception e) {
            }
        }
    }
    return networks;
}
Also used : LinkAddress(android.net.LinkAddress) Inet4Address(java.net.Inet4Address) IpConfiguration(android.net.IpConfiguration) StaticIpConfiguration(android.net.StaticIpConfiguration) IpAssignment(android.net.IpConfiguration.IpAssignment) ProxySettings(android.net.IpConfiguration.ProxySettings) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) EOFException(java.io.EOFException) ProxyInfo(android.net.ProxyInfo) SparseArray(android.util.SparseArray) BufferedInputStream(java.io.BufferedInputStream) StaticIpConfiguration(android.net.StaticIpConfiguration) EOFException(java.io.EOFException) RouteInfo(android.net.RouteInfo) InetAddress(java.net.InetAddress)

Example 5 with IpConfiguration

use of android.net.IpConfiguration in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiConfigController method getConfig.

/* package */
WifiConfiguration getConfig() {
    if (mMode == WifiConfigUiBase.MODE_VIEW) {
        return null;
    }
    WifiConfiguration config = new WifiConfiguration();
    if (mAccessPoint == null) {
        config.SSID = AccessPoint.convertToQuotedString(mSsidView.getText().toString());
        // If the user adds a network manually, assume that it is hidden.
        config.hiddenSSID = true;
    } else if (!mAccessPoint.isSaved()) {
        config.SSID = AccessPoint.convertToQuotedString(mAccessPoint.getSsidStr());
    } else {
        config.networkId = mAccessPoint.getConfig().networkId;
    }
    config.shared = mSharedCheckBox.isChecked();
    switch(mAccessPointSecurity) {
        case AccessPoint.SECURITY_NONE:
            config.allowedKeyManagement.set(KeyMgmt.NONE);
            break;
        case AccessPoint.SECURITY_WEP:
            config.allowedKeyManagement.set(KeyMgmt.NONE);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
            if (mPasswordView.length() != 0) {
                int length = mPasswordView.length();
                String password = mPasswordView.getText().toString();
                // WEP-40, WEP-104, and WEP128
                if ((length == 10 || length == 26 || length == 32) && password.matches("[0-9A-Fa-f]*")) {
                    config.wepKeys[0] = password;
                } else {
                    config.wepKeys[0] = '"' + password + '"';
                }
            }
            break;
        case AccessPoint.SECURITY_PSK:
            config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
            if (mPasswordView.length() != 0) {
                String password = mPasswordView.getText().toString();
                if (password.matches("[0-9A-Fa-f]{64}")) {
                    config.preSharedKey = password;
                } else {
                    config.preSharedKey = '"' + password + '"';
                }
            }
            break;
        case AccessPoint.SECURITY_EAP:
            config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
            config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
            config.enterpriseConfig = new WifiEnterpriseConfig();
            int eapMethod = mEapMethodSpinner.getSelectedItemPosition();
            int phase2Method = mPhase2Spinner.getSelectedItemPosition();
            config.enterpriseConfig.setEapMethod(eapMethod);
            switch(eapMethod) {
                case Eap.PEAP:
                    // by the API which has the full list of PEAP methods.
                    switch(phase2Method) {
                        case WIFI_PEAP_PHASE2_NONE:
                            config.enterpriseConfig.setPhase2Method(Phase2.NONE);
                            break;
                        case WIFI_PEAP_PHASE2_MSCHAPV2:
                            config.enterpriseConfig.setPhase2Method(Phase2.MSCHAPV2);
                            break;
                        case WIFI_PEAP_PHASE2_GTC:
                            config.enterpriseConfig.setPhase2Method(Phase2.GTC);
                            break;
                        default:
                            Log.e(TAG, "Unknown phase2 method" + phase2Method);
                            break;
                    }
                    break;
                case Eap.SIM:
                case Eap.AKA:
                case Eap.AKA_PRIME:
                    selectedSimCardNumber = mSimCardSpinner.getSelectedItemPosition() + 1;
                    config.SIMNum = selectedSimCardNumber;
                    break;
                default:
                    // The default index from mPhase2FullAdapter maps to the API
                    config.enterpriseConfig.setPhase2Method(phase2Method);
                    break;
            }
            String caCert = (String) mEapCaCertSpinner.getSelectedItem();
            config.enterpriseConfig.setCaCertificateAliases(null);
            config.enterpriseConfig.setCaPath(null);
            config.enterpriseConfig.setDomainSuffixMatch(mEapDomainView.getText().toString());
            if (caCert.equals(mUnspecifiedCertString) || caCert.equals(mDoNotValidateEapServerString)) {
            // ca_cert already set to null, so do nothing.
            } else if (caCert.equals(mUseSystemCertsString)) {
                config.enterpriseConfig.setCaPath(SYSTEM_CA_STORE_PATH);
            } else if (caCert.equals(mMultipleCertSetString)) {
                if (mAccessPoint != null) {
                    if (!mAccessPoint.isSaved()) {
                        Log.e(TAG, "Multiple certs can only be set " + "when editing saved network");
                    }
                    config.enterpriseConfig.setCaCertificateAliases(mAccessPoint.getConfig().enterpriseConfig.getCaCertificateAliases());
                }
            } else {
                config.enterpriseConfig.setCaCertificateAliases(new String[] { caCert });
            }
            // previously-set value on a saved configuration will be erased on an update.
            if (config.enterpriseConfig.getCaCertificateAliases() != null && config.enterpriseConfig.getCaPath() != null) {
                Log.e(TAG, "ca_cert (" + config.enterpriseConfig.getCaCertificateAliases() + ") and ca_path (" + config.enterpriseConfig.getCaPath() + ") should not both be non-null");
            }
            String clientCert = (String) mEapUserCertSpinner.getSelectedItem();
            if (clientCert.equals(mUnspecifiedCertString) || clientCert.equals(mDoNotProvideEapUserCertString)) {
                // Note: |clientCert| should not be able to take the value |unspecifiedCert|,
                // since we prevent such configurations from being saved.
                clientCert = "";
            }
            config.enterpriseConfig.setClientCertificateAlias(clientCert);
            if (eapMethod == Eap.SIM || eapMethod == Eap.AKA || eapMethod == Eap.AKA_PRIME) {
                config.enterpriseConfig.setIdentity("");
                config.enterpriseConfig.setAnonymousIdentity("");
            } else if (eapMethod == Eap.PWD) {
                config.enterpriseConfig.setIdentity(mEapIdentityView.getText().toString());
                config.enterpriseConfig.setAnonymousIdentity("");
            } else {
                config.enterpriseConfig.setIdentity(mEapIdentityView.getText().toString());
                config.enterpriseConfig.setAnonymousIdentity(mEapAnonymousView.getText().toString());
            }
            if (mPasswordView.isShown()) {
                // Update only if it has been changed.
                if (mPasswordView.length() > 0) {
                    config.enterpriseConfig.setPassword(mPasswordView.getText().toString());
                }
            } else {
                // clear password
                config.enterpriseConfig.setPassword(mPasswordView.getText().toString());
            }
            break;
        default:
            return null;
    }
    config.setIpConfiguration(new IpConfiguration(mIpAssignment, mProxySettings, mStaticIpConfiguration, mHttpProxy));
    return config;
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) StaticIpConfiguration(android.net.StaticIpConfiguration) IpConfiguration(android.net.IpConfiguration) WifiConfiguration(android.net.wifi.WifiConfiguration) AccessPoint(com.android.settingslib.wifi.AccessPoint)

Aggregations

IpConfiguration (android.net.IpConfiguration)6 StaticIpConfiguration (android.net.StaticIpConfiguration)6 IpAssignment (android.net.IpConfiguration.IpAssignment)5 ProxySettings (android.net.IpConfiguration.ProxySettings)5 LinkAddress (android.net.LinkAddress)5 ProxyInfo (android.net.ProxyInfo)5 RouteInfo (android.net.RouteInfo)5 SparseArray (android.util.SparseArray)5 DataInputStream (java.io.DataInputStream)5 EOFException (java.io.EOFException)5 IOException (java.io.IOException)5 Inet4Address (java.net.Inet4Address)5 InetAddress (java.net.InetAddress)5 BufferedInputStream (java.io.BufferedInputStream)4 FileInputStream (java.io.FileInputStream)4 WifiConfiguration (android.net.wifi.WifiConfiguration)1 WifiEnterpriseConfig (android.net.wifi.WifiEnterpriseConfig)1 AccessPoint (com.android.settingslib.wifi.AccessPoint)1 FileNotFoundException (java.io.FileNotFoundException)1