Bind addr and prefixLength together in LinkAddress
bug:2542681 Change-Id: I90200446216d78c676498144946832afe75efdb8
This commit is contained in:
@@ -28,8 +28,7 @@ import java.net.UnknownHostException;
|
||||
*/
|
||||
public class InterfaceConfiguration implements Parcelable {
|
||||
public String hwAddr;
|
||||
public InetAddress addr;
|
||||
public InetAddress mask;
|
||||
public LinkAddress addr;
|
||||
public String interfaceFlags;
|
||||
|
||||
public InterfaceConfiguration() {
|
||||
@@ -41,8 +40,6 @@ public class InterfaceConfiguration implements Parcelable {
|
||||
|
||||
str.append("ipddress ");
|
||||
str.append((addr != null) ? addr.toString() : "NULL");
|
||||
str.append(" netmask ");
|
||||
str.append((mask != null) ? mask.toString() : "NULL");
|
||||
str.append(" flags ").append(interfaceFlags);
|
||||
str.append(" hwaddr ").append(hwAddr);
|
||||
|
||||
@@ -59,7 +56,7 @@ public class InterfaceConfiguration implements Parcelable {
|
||||
public boolean isActive() {
|
||||
try {
|
||||
if(interfaceFlags.contains("up")) {
|
||||
for (byte b : addr.getAddress()) {
|
||||
for (byte b : addr.getAddress().getAddress()) {
|
||||
if (b != 0) return true;
|
||||
}
|
||||
}
|
||||
@@ -79,13 +76,7 @@ public class InterfaceConfiguration implements Parcelable {
|
||||
dest.writeString(hwAddr);
|
||||
if (addr != null) {
|
||||
dest.writeByte((byte)1);
|
||||
dest.writeByteArray(addr.getAddress());
|
||||
} else {
|
||||
dest.writeByte((byte)0);
|
||||
}
|
||||
if (mask != null) {
|
||||
dest.writeByte((byte)1);
|
||||
dest.writeByteArray(mask.getAddress());
|
||||
dest.writeParcelable(addr, flags);
|
||||
} else {
|
||||
dest.writeByte((byte)0);
|
||||
}
|
||||
@@ -99,14 +90,7 @@ public class InterfaceConfiguration implements Parcelable {
|
||||
InterfaceConfiguration info = new InterfaceConfiguration();
|
||||
info.hwAddr = in.readString();
|
||||
if (in.readByte() == 1) {
|
||||
try {
|
||||
info.addr = InetAddress.getByAddress(in.createByteArray());
|
||||
} catch (UnknownHostException e) {}
|
||||
}
|
||||
if (in.readByte() == 1) {
|
||||
try {
|
||||
info.mask = InetAddress.getByAddress(in.createByteArray());
|
||||
} catch (UnknownHostException e) {}
|
||||
info.addr = in.readParcelable(null);
|
||||
}
|
||||
info.interfaceFlags = in.readString();
|
||||
return info;
|
||||
|
||||
@@ -47,6 +47,7 @@ import android.content.SharedPreferences;
|
||||
import android.content.res.Resources.NotFoundException;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.InterfaceConfiguration;
|
||||
import android.net.LinkAddress;
|
||||
import android.os.Binder;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
@@ -1697,12 +1698,15 @@ public class BluetoothService extends IBluetooth.Stub {
|
||||
try {
|
||||
ifcg = service.getInterfaceConfig(iface);
|
||||
if (ifcg != null) {
|
||||
ifcg.mask = InetAddress.getByName(BLUETOOTH_NETMASK);
|
||||
|
||||
if (ifcg.addr == null || ifcg.addr.equals(InetAddress.getByName("0.0.0.0"))) {
|
||||
ifcg.addr = InetAddress.getByName(address);
|
||||
ifcg.interfaceFlags = ifcg.interfaceFlags.replace("down", "up");
|
||||
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")) ||
|
||||
addr.equals(InetAddress.getByName("::0"))) {
|
||||
addr = InetAddress.getByName(address);
|
||||
}
|
||||
ifcg.interfaceFlags = ifcg.interfaceFlags.replace("down", "up");
|
||||
ifcg.addr = new LinkAddress(addr, mask);
|
||||
ifcg.interfaceFlags = ifcg.interfaceFlags.replace("running", "");
|
||||
ifcg.interfaceFlags = ifcg.interfaceFlags.replace(" "," ");
|
||||
service.setInterfaceConfig(iface, ifcg);
|
||||
|
||||
Reference in New Issue
Block a user