Loading core/java/android/net/LinkAddress.java +16 −16 Original line number Diff line number Diff line Loading @@ -34,26 +34,26 @@ public class LinkAddress implements Parcelable { private final InetAddress address; /** * Network prefix * Network prefix length */ private final int prefix; private final int prefixLength; public LinkAddress(InetAddress address, InetAddress mask) { this.address = address; this.prefix = computeprefix(mask); this.prefixLength = computeprefixLength(mask); } public LinkAddress(InetAddress address, int prefix) { public LinkAddress(InetAddress address, int prefixLength) { this.address = address; this.prefix = prefix; this.prefixLength = prefixLength; } public LinkAddress(InterfaceAddress interfaceAddress) { this.address = interfaceAddress.getAddress(); this.prefix = interfaceAddress.getNetworkPrefixLength(); this.prefixLength = interfaceAddress.getNetworkPrefixLength(); } private static int computeprefix(InetAddress mask) { private static int computeprefixLength(InetAddress mask) { int count = 0; for (byte b : mask.getAddress()) { for (int i = 0; i < 8; ++i) { Loading @@ -67,12 +67,12 @@ public class LinkAddress implements Parcelable { @Override public String toString() { return (address == null ? "" : (address.getHostAddress() + "/" + prefix)); return (address == null ? "" : (address.getHostAddress() + "/" + prefixLength)); } /** * Compares this {@code LinkAddress} instance against the specified address * in {@code obj}. Two addresses are equal if their InetAddress and prefix * in {@code obj}. Two addresses are equal if their InetAddress and prefixLength * are equal * * @param obj the object to be tested for equality. Loading @@ -85,7 +85,7 @@ public class LinkAddress implements Parcelable { } LinkAddress linkAddress = (LinkAddress) obj; return this.address.equals(linkAddress.address) && this.prefix == linkAddress.prefix; this.prefixLength == linkAddress.prefixLength; } /** Loading @@ -98,8 +98,8 @@ public class LinkAddress implements Parcelable { /** * Get network prefix length */ public int getNetworkPrefix() { return prefix; public int getNetworkPrefixLength() { return prefixLength; } /** Loading @@ -118,7 +118,7 @@ public class LinkAddress implements Parcelable { if (address != null) { dest.writeByte((byte)1); dest.writeByteArray(address.getAddress()); dest.writeInt(prefix); dest.writeInt(prefixLength); } else { dest.writeByte((byte)0); } Loading @@ -132,14 +132,14 @@ public class LinkAddress implements Parcelable { new Creator<LinkAddress>() { public LinkAddress createFromParcel(Parcel in) { InetAddress address = null; int prefix = 0; int prefixLength = 0; if (in.readByte() == 1) { try { address = InetAddress.getByAddress(in.createByteArray()); prefix = in.readInt(); prefixLength = in.readInt(); } catch (UnknownHostException e) { } } return new LinkAddress(address, prefix); return new LinkAddress(address, prefixLength); } public LinkAddress[] newArray(int size) { Loading core/java/android/net/NetworkUtils.java +51 −0 Original line number Diff line number Diff line Loading @@ -145,6 +145,57 @@ public class NetworkUtils { return inetAddress; } /** * Convert a IPv4 address from an InetAddress to an integer * @param inetAddr is an InetAddress corresponding to the IPv4 address * @return the IP address as an integer in network byte order */ public static int inetAddressToInt(InetAddress inetAddr) throws IllegalArgumentException { byte [] addr = inetAddr.getAddress(); if (addr.length != 4) { throw new IllegalArgumentException("Not an IPv4 address"); } return ((addr[3] & 0xff) << 24) | ((addr[2] & 0xff) << 16) | ((addr[1] & 0xff) << 8) | (addr[0] & 0xff); } /** * Convert a network prefix length to an IPv4 netmask integer * @param prefixLength * @return the IPv4 netmask as an integer in network byte order */ public static int prefixLengthToNetmaskInt(int prefixLength) throws IllegalArgumentException { if (prefixLength < 0 || prefixLength > 32) { throw new IllegalArgumentException("Invalid prefix length (0 <= prefix <= 32)"); } int value = 0xffffffff << (32 - prefixLength); return Integer.reverseBytes(value); } public static boolean isIpAddress(String address) { //TODO: Add NetworkUtils support for IPv6 configuration and //remove IPv4 validation and use a generic InetAddress validation try { String[] parts = address.split("\\."); if (parts.length != 4) { return false; } int a = Integer.parseInt(parts[0]); if (a < 0 || a > 255) return false; a = Integer.parseInt(parts[1]); if (a < 0 || a > 255) return false; a = Integer.parseInt(parts[2]); if (a < 0 || a > 255) return false; a = Integer.parseInt(parts[3]); if (a < 0 || a > 255) return false; } catch (NumberFormatException ex) { return false; } return true; } /** * Add a default route through the specified gateway. * @param interfaceName interface on which the route should be added Loading wifi/java/android/net/wifi/WifiConfigStore.java +286 −151 File changed.Preview size limit exceeded, changes collapsed. Show changes wifi/java/android/net/wifi/WifiConfiguration.java +14 −39 Original line number Diff line number Diff line Loading @@ -16,8 +16,7 @@ package android.net.wifi; import android.net.DhcpInfo; import android.net.ProxyProperties; import android.net.LinkProperties; import android.os.Parcelable; import android.os.Parcel; Loading Loading @@ -303,7 +302,7 @@ public class WifiConfiguration implements Parcelable { */ public enum IpAssignment { /* Use statically configured IP settings. Configuration can be accessed * with ipConfig */ * with linkProperties */ STATIC, /* Use dynamically configured IP settigns */ DHCP, Loading @@ -315,10 +314,6 @@ public class WifiConfiguration implements Parcelable { * @hide */ public IpAssignment ipAssignment; /** * @hide */ public DhcpInfo ipConfig; /** * @hide Loading @@ -328,7 +323,7 @@ public class WifiConfiguration implements Parcelable { * should be cleared. */ NONE, /* Use statically configured proxy. Configuration can be accessed * with proxyProperties */ * with linkProperties */ STATIC, /* no proxy details are assigned, this is used to indicate * that any existing proxy settings should be retained */ Loading @@ -341,7 +336,7 @@ public class WifiConfiguration implements Parcelable { /** * @hide */ public ProxyProperties proxyProperties; public LinkProperties linkProperties; public WifiConfiguration() { networkId = INVALID_NETWORK_ID; Loading @@ -361,9 +356,8 @@ public class WifiConfiguration implements Parcelable { field.setValue(null); } ipAssignment = IpAssignment.UNASSIGNED; ipConfig = new DhcpInfo(); proxySettings = ProxySettings.UNASSIGNED; proxyProperties = new ProxyProperties(); linkProperties = new LinkProperties(); } public String toString() { Loading Loading @@ -445,17 +439,13 @@ public class WifiConfiguration implements Parcelable { if (value != null) sbuf.append(value); } sbuf.append('\n'); if (ipAssignment == IpAssignment.STATIC) { sbuf.append(" ").append("Static IP configuration:").append('\n'); sbuf.append(" ").append(ipConfig); } sbuf.append('\n'); sbuf.append("IP assignment: " + ipAssignment.toString()); sbuf.append("\n"); sbuf.append("Proxy settings: " + proxySettings.toString()); sbuf.append("\n"); sbuf.append(linkProperties.toString()); sbuf.append("\n"); if (proxySettings == ProxySettings.STATIC) { sbuf.append(" ").append("Proxy configuration:").append('\n'); sbuf.append(" ").append(proxyProperties); } sbuf.append('\n'); return sbuf.toString(); } Loading Loading @@ -521,9 +511,8 @@ public class WifiConfiguration implements Parcelable { enterpriseFields[i].setValue(source.enterpriseFields[i].value()); } ipAssignment = source.ipAssignment; ipConfig = new DhcpInfo(source.ipConfig); proxySettings = source.proxySettings; proxyProperties = new ProxyProperties(source.proxyProperties); linkProperties = new LinkProperties(source.linkProperties); } } Loading @@ -550,15 +539,8 @@ public class WifiConfiguration implements Parcelable { dest.writeString(field.value()); } dest.writeString(ipAssignment.name()); dest.writeInt(ipConfig.ipAddress); dest.writeInt(ipConfig.netmask); dest.writeInt(ipConfig.gateway); dest.writeInt(ipConfig.dns1); dest.writeInt(ipConfig.dns2); dest.writeInt(ipConfig.serverAddress); dest.writeInt(ipConfig.leaseDuration); dest.writeString(proxySettings.name()); dest.writeParcelable(proxyProperties, flags); dest.writeParcelable(linkProperties, flags); } /** Implement the Parcelable interface {@hide} */ Loading Loading @@ -587,15 +569,8 @@ public class WifiConfiguration implements Parcelable { } config.ipAssignment = IpAssignment.valueOf(in.readString()); config.ipConfig.ipAddress = in.readInt(); config.ipConfig.netmask = in.readInt(); config.ipConfig.gateway = in.readInt(); config.ipConfig.dns1 = in.readInt(); config.ipConfig.dns2 = in.readInt(); config.ipConfig.serverAddress = in.readInt(); config.ipConfig.leaseDuration = in.readInt(); config.proxySettings = ProxySettings.valueOf(in.readString()); config.proxyProperties = in.readParcelable(null); config.linkProperties = in.readParcelable(null); return config; } Loading wifi/java/android/net/wifi/WifiStateMachine.java +15 −19 Original line number Diff line number Diff line Loading @@ -1253,9 +1253,9 @@ public class WifiStateMachine extends HierarchicalStateMachine { } private void configureLinkProperties() { mLinkProperties.setInterfaceName(mInterfaceName); if (WifiConfigStore.isUsingStaticIp(mLastNetworkId)) { mLinkProperties = WifiConfigStore.getLinkProperties(mLastNetworkId); } else { // TODO - fix this for v6 synchronized (mDhcpInfo) { mLinkProperties.addLinkAddress(new LinkAddress( Loading @@ -1265,13 +1265,10 @@ public class WifiStateMachine extends HierarchicalStateMachine { mLinkProperties.addDns(NetworkUtils.intToInetAddress(mDhcpInfo.dns1)); mLinkProperties.addDns(NetworkUtils.intToInetAddress(mDhcpInfo.dns2)); } ProxyProperties proxyProperties = WifiConfigStore.getProxyProperties(mLastNetworkId); if (proxyProperties != null) { mLinkProperties.setHttpProxy(proxyProperties); Log.d(TAG, "netId=" + mLastNetworkId + " proxy configured: " + proxyProperties.toString()); mLinkProperties.setHttpProxy(WifiConfigStore.getProxyProperties(mLastNetworkId)); } mLinkProperties.setInterfaceName(mInterfaceName); Log.d(TAG, "netId=" + mLastNetworkId + " Link configured: " + mLinkProperties.toString()); } private int getMaxDhcpRetries() { Loading Loading @@ -2571,7 +2568,6 @@ public class WifiStateMachine extends HierarchicalStateMachine { mLastSignalLevel = -1; // force update of signal strength synchronized (mDhcpInfo) { mWifiInfo.setIpAddress(mDhcpInfo.ipAddress); Log.d(TAG, "IP configuration: " + mDhcpInfo); } configureLinkProperties(); setDetailedState(DetailedState.CONNECTED); Loading Loading
core/java/android/net/LinkAddress.java +16 −16 Original line number Diff line number Diff line Loading @@ -34,26 +34,26 @@ public class LinkAddress implements Parcelable { private final InetAddress address; /** * Network prefix * Network prefix length */ private final int prefix; private final int prefixLength; public LinkAddress(InetAddress address, InetAddress mask) { this.address = address; this.prefix = computeprefix(mask); this.prefixLength = computeprefixLength(mask); } public LinkAddress(InetAddress address, int prefix) { public LinkAddress(InetAddress address, int prefixLength) { this.address = address; this.prefix = prefix; this.prefixLength = prefixLength; } public LinkAddress(InterfaceAddress interfaceAddress) { this.address = interfaceAddress.getAddress(); this.prefix = interfaceAddress.getNetworkPrefixLength(); this.prefixLength = interfaceAddress.getNetworkPrefixLength(); } private static int computeprefix(InetAddress mask) { private static int computeprefixLength(InetAddress mask) { int count = 0; for (byte b : mask.getAddress()) { for (int i = 0; i < 8; ++i) { Loading @@ -67,12 +67,12 @@ public class LinkAddress implements Parcelable { @Override public String toString() { return (address == null ? "" : (address.getHostAddress() + "/" + prefix)); return (address == null ? "" : (address.getHostAddress() + "/" + prefixLength)); } /** * Compares this {@code LinkAddress} instance against the specified address * in {@code obj}. Two addresses are equal if their InetAddress and prefix * in {@code obj}. Two addresses are equal if their InetAddress and prefixLength * are equal * * @param obj the object to be tested for equality. Loading @@ -85,7 +85,7 @@ public class LinkAddress implements Parcelable { } LinkAddress linkAddress = (LinkAddress) obj; return this.address.equals(linkAddress.address) && this.prefix == linkAddress.prefix; this.prefixLength == linkAddress.prefixLength; } /** Loading @@ -98,8 +98,8 @@ public class LinkAddress implements Parcelable { /** * Get network prefix length */ public int getNetworkPrefix() { return prefix; public int getNetworkPrefixLength() { return prefixLength; } /** Loading @@ -118,7 +118,7 @@ public class LinkAddress implements Parcelable { if (address != null) { dest.writeByte((byte)1); dest.writeByteArray(address.getAddress()); dest.writeInt(prefix); dest.writeInt(prefixLength); } else { dest.writeByte((byte)0); } Loading @@ -132,14 +132,14 @@ public class LinkAddress implements Parcelable { new Creator<LinkAddress>() { public LinkAddress createFromParcel(Parcel in) { InetAddress address = null; int prefix = 0; int prefixLength = 0; if (in.readByte() == 1) { try { address = InetAddress.getByAddress(in.createByteArray()); prefix = in.readInt(); prefixLength = in.readInt(); } catch (UnknownHostException e) { } } return new LinkAddress(address, prefix); return new LinkAddress(address, prefixLength); } public LinkAddress[] newArray(int size) { Loading
core/java/android/net/NetworkUtils.java +51 −0 Original line number Diff line number Diff line Loading @@ -145,6 +145,57 @@ public class NetworkUtils { return inetAddress; } /** * Convert a IPv4 address from an InetAddress to an integer * @param inetAddr is an InetAddress corresponding to the IPv4 address * @return the IP address as an integer in network byte order */ public static int inetAddressToInt(InetAddress inetAddr) throws IllegalArgumentException { byte [] addr = inetAddr.getAddress(); if (addr.length != 4) { throw new IllegalArgumentException("Not an IPv4 address"); } return ((addr[3] & 0xff) << 24) | ((addr[2] & 0xff) << 16) | ((addr[1] & 0xff) << 8) | (addr[0] & 0xff); } /** * Convert a network prefix length to an IPv4 netmask integer * @param prefixLength * @return the IPv4 netmask as an integer in network byte order */ public static int prefixLengthToNetmaskInt(int prefixLength) throws IllegalArgumentException { if (prefixLength < 0 || prefixLength > 32) { throw new IllegalArgumentException("Invalid prefix length (0 <= prefix <= 32)"); } int value = 0xffffffff << (32 - prefixLength); return Integer.reverseBytes(value); } public static boolean isIpAddress(String address) { //TODO: Add NetworkUtils support for IPv6 configuration and //remove IPv4 validation and use a generic InetAddress validation try { String[] parts = address.split("\\."); if (parts.length != 4) { return false; } int a = Integer.parseInt(parts[0]); if (a < 0 || a > 255) return false; a = Integer.parseInt(parts[1]); if (a < 0 || a > 255) return false; a = Integer.parseInt(parts[2]); if (a < 0 || a > 255) return false; a = Integer.parseInt(parts[3]); if (a < 0 || a > 255) return false; } catch (NumberFormatException ex) { return false; } return true; } /** * Add a default route through the specified gateway. * @param interfaceName interface on which the route should be added Loading
wifi/java/android/net/wifi/WifiConfigStore.java +286 −151 File changed.Preview size limit exceeded, changes collapsed. Show changes
wifi/java/android/net/wifi/WifiConfiguration.java +14 −39 Original line number Diff line number Diff line Loading @@ -16,8 +16,7 @@ package android.net.wifi; import android.net.DhcpInfo; import android.net.ProxyProperties; import android.net.LinkProperties; import android.os.Parcelable; import android.os.Parcel; Loading Loading @@ -303,7 +302,7 @@ public class WifiConfiguration implements Parcelable { */ public enum IpAssignment { /* Use statically configured IP settings. Configuration can be accessed * with ipConfig */ * with linkProperties */ STATIC, /* Use dynamically configured IP settigns */ DHCP, Loading @@ -315,10 +314,6 @@ public class WifiConfiguration implements Parcelable { * @hide */ public IpAssignment ipAssignment; /** * @hide */ public DhcpInfo ipConfig; /** * @hide Loading @@ -328,7 +323,7 @@ public class WifiConfiguration implements Parcelable { * should be cleared. */ NONE, /* Use statically configured proxy. Configuration can be accessed * with proxyProperties */ * with linkProperties */ STATIC, /* no proxy details are assigned, this is used to indicate * that any existing proxy settings should be retained */ Loading @@ -341,7 +336,7 @@ public class WifiConfiguration implements Parcelable { /** * @hide */ public ProxyProperties proxyProperties; public LinkProperties linkProperties; public WifiConfiguration() { networkId = INVALID_NETWORK_ID; Loading @@ -361,9 +356,8 @@ public class WifiConfiguration implements Parcelable { field.setValue(null); } ipAssignment = IpAssignment.UNASSIGNED; ipConfig = new DhcpInfo(); proxySettings = ProxySettings.UNASSIGNED; proxyProperties = new ProxyProperties(); linkProperties = new LinkProperties(); } public String toString() { Loading Loading @@ -445,17 +439,13 @@ public class WifiConfiguration implements Parcelable { if (value != null) sbuf.append(value); } sbuf.append('\n'); if (ipAssignment == IpAssignment.STATIC) { sbuf.append(" ").append("Static IP configuration:").append('\n'); sbuf.append(" ").append(ipConfig); } sbuf.append('\n'); sbuf.append("IP assignment: " + ipAssignment.toString()); sbuf.append("\n"); sbuf.append("Proxy settings: " + proxySettings.toString()); sbuf.append("\n"); sbuf.append(linkProperties.toString()); sbuf.append("\n"); if (proxySettings == ProxySettings.STATIC) { sbuf.append(" ").append("Proxy configuration:").append('\n'); sbuf.append(" ").append(proxyProperties); } sbuf.append('\n'); return sbuf.toString(); } Loading Loading @@ -521,9 +511,8 @@ public class WifiConfiguration implements Parcelable { enterpriseFields[i].setValue(source.enterpriseFields[i].value()); } ipAssignment = source.ipAssignment; ipConfig = new DhcpInfo(source.ipConfig); proxySettings = source.proxySettings; proxyProperties = new ProxyProperties(source.proxyProperties); linkProperties = new LinkProperties(source.linkProperties); } } Loading @@ -550,15 +539,8 @@ public class WifiConfiguration implements Parcelable { dest.writeString(field.value()); } dest.writeString(ipAssignment.name()); dest.writeInt(ipConfig.ipAddress); dest.writeInt(ipConfig.netmask); dest.writeInt(ipConfig.gateway); dest.writeInt(ipConfig.dns1); dest.writeInt(ipConfig.dns2); dest.writeInt(ipConfig.serverAddress); dest.writeInt(ipConfig.leaseDuration); dest.writeString(proxySettings.name()); dest.writeParcelable(proxyProperties, flags); dest.writeParcelable(linkProperties, flags); } /** Implement the Parcelable interface {@hide} */ Loading Loading @@ -587,15 +569,8 @@ public class WifiConfiguration implements Parcelable { } config.ipAssignment = IpAssignment.valueOf(in.readString()); config.ipConfig.ipAddress = in.readInt(); config.ipConfig.netmask = in.readInt(); config.ipConfig.gateway = in.readInt(); config.ipConfig.dns1 = in.readInt(); config.ipConfig.dns2 = in.readInt(); config.ipConfig.serverAddress = in.readInt(); config.ipConfig.leaseDuration = in.readInt(); config.proxySettings = ProxySettings.valueOf(in.readString()); config.proxyProperties = in.readParcelable(null); config.linkProperties = in.readParcelable(null); return config; } Loading
wifi/java/android/net/wifi/WifiStateMachine.java +15 −19 Original line number Diff line number Diff line Loading @@ -1253,9 +1253,9 @@ public class WifiStateMachine extends HierarchicalStateMachine { } private void configureLinkProperties() { mLinkProperties.setInterfaceName(mInterfaceName); if (WifiConfigStore.isUsingStaticIp(mLastNetworkId)) { mLinkProperties = WifiConfigStore.getLinkProperties(mLastNetworkId); } else { // TODO - fix this for v6 synchronized (mDhcpInfo) { mLinkProperties.addLinkAddress(new LinkAddress( Loading @@ -1265,13 +1265,10 @@ public class WifiStateMachine extends HierarchicalStateMachine { mLinkProperties.addDns(NetworkUtils.intToInetAddress(mDhcpInfo.dns1)); mLinkProperties.addDns(NetworkUtils.intToInetAddress(mDhcpInfo.dns2)); } ProxyProperties proxyProperties = WifiConfigStore.getProxyProperties(mLastNetworkId); if (proxyProperties != null) { mLinkProperties.setHttpProxy(proxyProperties); Log.d(TAG, "netId=" + mLastNetworkId + " proxy configured: " + proxyProperties.toString()); mLinkProperties.setHttpProxy(WifiConfigStore.getProxyProperties(mLastNetworkId)); } mLinkProperties.setInterfaceName(mInterfaceName); Log.d(TAG, "netId=" + mLastNetworkId + " Link configured: " + mLinkProperties.toString()); } private int getMaxDhcpRetries() { Loading Loading @@ -2571,7 +2568,6 @@ public class WifiStateMachine extends HierarchicalStateMachine { mLastSignalLevel = -1; // force update of signal strength synchronized (mDhcpInfo) { mWifiInfo.setIpAddress(mDhcpInfo.ipAddress); Log.d(TAG, "IP configuration: " + mDhcpInfo); } configureLinkProperties(); setDetailedState(DetailedState.CONNECTED); Loading