Remove more use of netmask
bug:2542681 Change-Id: Ifd75672739ee8262d4df22afd8173e4f3f67260d
This commit is contained in:
@ -19,6 +19,7 @@ package android.net;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InterfaceAddress;
|
||||
import java.net.UnknownHostException;
|
||||
@ -38,12 +39,13 @@ public class LinkAddress implements Parcelable {
|
||||
*/
|
||||
private final int prefixLength;
|
||||
|
||||
public LinkAddress(InetAddress address, InetAddress mask) {
|
||||
this.address = address;
|
||||
this.prefixLength = computeprefixLength(mask);
|
||||
}
|
||||
|
||||
public LinkAddress(InetAddress address, int prefixLength) {
|
||||
if (address == null || prefixLength < 0 ||
|
||||
((address instanceof Inet4Address) && prefixLength > 32) ||
|
||||
(prefixLength > 128)) {
|
||||
throw new IllegalArgumentException("Bad LinkAddress params " + address +
|
||||
prefixLength);
|
||||
}
|
||||
this.address = address;
|
||||
this.prefixLength = prefixLength;
|
||||
}
|
||||
@ -53,18 +55,6 @@ public class LinkAddress implements Parcelable {
|
||||
this.prefixLength = interfaceAddress.getNetworkPrefixLength();
|
||||
}
|
||||
|
||||
private static int computeprefixLength(InetAddress mask) {
|
||||
int count = 0;
|
||||
for (byte b : mask.getAddress()) {
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
if ((b & (1 << i)) != 0) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return (address == null ? "" : (address.getHostAddress() + "/" + prefixLength));
|
||||
|
@ -130,7 +130,7 @@ public class BluetoothService extends IBluetooth.Stub {
|
||||
|
||||
private static final String BLUETOOTH_IFACE_ADDR_START= "192.168.44.1";
|
||||
private static final int BLUETOOTH_MAX_PAN_CONNECTIONS = 5;
|
||||
private static final String BLUETOOTH_NETMASK = "255.255.255.0";
|
||||
private static final int BLUETOOTH_PREFIX_LENGTH = 24;
|
||||
|
||||
// The timeout used to sent the UUIDs Intent
|
||||
// This timeout should be greater than the page timeout
|
||||
@ -1704,7 +1704,6 @@ public class BluetoothService extends IBluetooth.Stub {
|
||||
try {
|
||||
ifcg = service.getInterfaceConfig(iface);
|
||||
if (ifcg != null) {
|
||||
InetAddress mask = InetAddress.getByName(BLUETOOTH_NETMASK);
|
||||
InetAddress addr = null;
|
||||
if (ifcg.addr == null || (addr = ifcg.addr.getAddress()) == null ||
|
||||
addr.equals(InetAddress.getByName("0.0.0.0")) ||
|
||||
@ -1712,7 +1711,7 @@ public class BluetoothService extends IBluetooth.Stub {
|
||||
addr = InetAddress.getByName(address);
|
||||
}
|
||||
ifcg.interfaceFlags = ifcg.interfaceFlags.replace("down", "up");
|
||||
ifcg.addr = new LinkAddress(addr, mask);
|
||||
ifcg.addr = new LinkAddress(addr, BLUETOOTH_PREFIX_LENGTH);
|
||||
ifcg.interfaceFlags = ifcg.interfaceFlags.replace("running", "");
|
||||
ifcg.interfaceFlags = ifcg.interfaceFlags.replace(" "," ");
|
||||
service.setInterfaceConfig(iface, ifcg);
|
||||
|
Reference in New Issue
Block a user