Merge changes from topic "ipsec-resource-id-cleanup" am: 2b36299c73 am: d7319df4d0
am: f81e9dcf6a
Change-Id: Ib96b30bcb1b47c23d0a18cf043dd042409c61322
This commit is contained in:
@@ -102,17 +102,11 @@ public final class IpSecConfig implements Parcelable {
|
||||
|
||||
/** Set the local IP address for Tunnel mode */
|
||||
public void setLocalAddress(String localAddress) {
|
||||
if (localAddress == null) {
|
||||
throw new IllegalArgumentException("localAddress may not be null!");
|
||||
}
|
||||
mLocalAddress = localAddress;
|
||||
}
|
||||
|
||||
/** Set the remote IP address for this IPsec transform */
|
||||
public void setRemoteAddress(String remoteAddress) {
|
||||
if (remoteAddress == null) {
|
||||
throw new IllegalArgumentException("remoteAddress may not be null!");
|
||||
}
|
||||
mRemoteAddress = remoteAddress;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ public final class IpSecManager {
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static final int INVALID_RESOURCE_ID = 0;
|
||||
public static final int INVALID_RESOURCE_ID = -1;
|
||||
|
||||
/**
|
||||
* Thrown to indicate that a requested SPI is in use.
|
||||
@@ -128,7 +128,7 @@ public final class IpSecManager {
|
||||
private final InetAddress mRemoteAddress;
|
||||
private final CloseGuard mCloseGuard = CloseGuard.get();
|
||||
private int mSpi = INVALID_SECURITY_PARAMETER_INDEX;
|
||||
private int mResourceId;
|
||||
private int mResourceId = INVALID_RESOURCE_ID;
|
||||
|
||||
/** Get the underlying SPI held by this object. */
|
||||
public int getSpi() {
|
||||
@@ -146,6 +146,7 @@ public final class IpSecManager {
|
||||
public void close() {
|
||||
try {
|
||||
mService.releaseSecurityParameterIndex(mResourceId);
|
||||
mResourceId = INVALID_RESOURCE_ID;
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -501,7 +502,7 @@ public final class IpSecManager {
|
||||
public static final class UdpEncapsulationSocket implements AutoCloseable {
|
||||
private final ParcelFileDescriptor mPfd;
|
||||
private final IIpSecService mService;
|
||||
private final int mResourceId;
|
||||
private int mResourceId = INVALID_RESOURCE_ID;
|
||||
private final int mPort;
|
||||
private final CloseGuard mCloseGuard = CloseGuard.get();
|
||||
|
||||
@@ -554,6 +555,7 @@ public final class IpSecManager {
|
||||
public void close() throws IOException {
|
||||
try {
|
||||
mService.closeUdpEncapsulationSocket(mResourceId);
|
||||
mResourceId = INVALID_RESOURCE_ID;
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
|
||||
@@ -347,6 +347,9 @@ public final class IpSecTransform implements AutoCloseable {
|
||||
*/
|
||||
public IpSecTransform.Builder setSpi(
|
||||
@TransformDirection int direction, IpSecManager.SecurityParameterIndex spi) {
|
||||
if (spi.getResourceId() == INVALID_RESOURCE_ID) {
|
||||
throw new IllegalArgumentException("Invalid SecurityParameterIndex");
|
||||
}
|
||||
mConfig.setSpiResourceId(direction, spi.getResourceId());
|
||||
return this;
|
||||
}
|
||||
@@ -381,6 +384,9 @@ public final class IpSecTransform implements AutoCloseable {
|
||||
public IpSecTransform.Builder setIpv4Encapsulation(
|
||||
IpSecManager.UdpEncapsulationSocket localSocket, int remotePort) {
|
||||
mConfig.setEncapType(ENCAP_ESPINUDP);
|
||||
if (localSocket.getResourceId() == INVALID_RESOURCE_ID) {
|
||||
throw new IllegalArgumentException("Invalid UdpEncapsulationSocket");
|
||||
}
|
||||
mConfig.setEncapSocketResourceId(localSocket.getResourceId());
|
||||
mConfig.setEncapRemotePort(remotePort);
|
||||
return this;
|
||||
@@ -426,6 +432,9 @@ public final class IpSecTransform implements AutoCloseable {
|
||||
public IpSecTransform buildTransportModeTransform(InetAddress remoteAddress)
|
||||
throws IpSecManager.ResourceUnavailableException,
|
||||
IpSecManager.SpiUnavailableException, IOException {
|
||||
if (remoteAddress == null) {
|
||||
throw new IllegalArgumentException("Remote address may not be null or empty!");
|
||||
}
|
||||
mConfig.setMode(MODE_TRANSPORT);
|
||||
mConfig.setRemoteAddress(remoteAddress.getHostAddress());
|
||||
// FIXME: modifying a builder after calling build can change the built transform.
|
||||
@@ -447,8 +456,12 @@ public final class IpSecTransform implements AutoCloseable {
|
||||
*/
|
||||
public IpSecTransform buildTunnelModeTransform(
|
||||
InetAddress localAddress, InetAddress remoteAddress) {
|
||||
// FIXME: argument validation here
|
||||
// throw new IllegalArgumentException("Natt Keepalive requires UDP Encapsulation");
|
||||
if (localAddress == null) {
|
||||
throw new IllegalArgumentException("Local address may not be null or empty!");
|
||||
}
|
||||
if (remoteAddress == null) {
|
||||
throw new IllegalArgumentException("Remote address may not be null or empty!");
|
||||
}
|
||||
mConfig.setLocalAddress(localAddress.getHostAddress());
|
||||
mConfig.setRemoteAddress(remoteAddress.getHostAddress());
|
||||
mConfig.setMode(MODE_TUNNEL);
|
||||
|
||||
Reference in New Issue
Block a user