Rework Exception Handling for IpSecManager
In order to properly support EOPNOTSUPP this CL applies a consistent approach to handling Exceptions. Hereafter, all exceptions that aren't of a special method-specific type (such as SpiUnavailableException) will all be returned to the calling process unchanged. At the API call site, the ServiceSpecificException, which is really an Errno, will be inspected and either converted to an unchecked exception for types we know, or it will be converted to an IOException in cases where that method can return a checked exception. In cases where we do not expect an errno, we will simply throw a generic RuntimeException. This means all API calls will now properly throw UnsupportedOperationException and may be CTS tested accordingly. Bug: 72420898 Test: runtest frameworks-net Change-Id: I4a00e221618896223fcdb4b4279fb14cd14e34d8
This commit is contained in:
@@ -1101,9 +1101,11 @@ public class IpSecService extends IIpSecService.Stub {
|
||||
new RefcountedResource<SpiRecord>(
|
||||
new SpiRecord(resourceId, "", destinationAddress, spi), binder));
|
||||
} catch (ServiceSpecificException e) {
|
||||
// TODO: Add appropriate checks when other ServiceSpecificException types are supported
|
||||
return new IpSecSpiResponse(
|
||||
IpSecManager.Status.SPI_UNAVAILABLE, INVALID_RESOURCE_ID, spi);
|
||||
if (e.errorCode == OsConstants.ENOENT) {
|
||||
return new IpSecSpiResponse(
|
||||
IpSecManager.Status.SPI_UNAVAILABLE, INVALID_RESOURCE_ID, spi);
|
||||
}
|
||||
throw e;
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -1115,7 +1117,6 @@ public class IpSecService extends IIpSecService.Stub {
|
||||
*/
|
||||
private void releaseResource(RefcountedResourceArray resArray, int resourceId)
|
||||
throws RemoteException {
|
||||
|
||||
resArray.getRefcountedResourceOrThrow(resourceId).userRelease();
|
||||
}
|
||||
|
||||
@@ -1315,15 +1316,12 @@ public class IpSecService extends IIpSecService.Stub {
|
||||
releaseNetId(ikey);
|
||||
releaseNetId(okey);
|
||||
throw e.rethrowFromSystemServer();
|
||||
} catch (ServiceSpecificException e) {
|
||||
// FIXME: get the error code and throw is at an IOException from Errno Exception
|
||||
} catch (Throwable t) {
|
||||
// Release keys if we got an error.
|
||||
releaseNetId(ikey);
|
||||
releaseNetId(okey);
|
||||
throw t;
|
||||
}
|
||||
|
||||
// If we make it to here, then something has gone wrong and we couldn't create a VTI.
|
||||
// Release the keys that we reserved, and return an error status.
|
||||
releaseNetId(ikey);
|
||||
releaseNetId(okey);
|
||||
return new IpSecTunnelInterfaceResponse(IpSecManager.Status.RESOURCE_UNAVAILABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1352,9 +1350,6 @@ public class IpSecService extends IIpSecService.Stub {
|
||||
localAddr.getPrefixLength());
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
} catch (ServiceSpecificException e) {
|
||||
// If we get here, one of the arguments provided was invalid. Wrap the SSE, and throw.
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1384,9 +1379,6 @@ public class IpSecService extends IIpSecService.Stub {
|
||||
localAddr.getPrefixLength());
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
} catch (ServiceSpecificException e) {
|
||||
// If we get here, one of the arguments provided was invalid. Wrap the SSE, and throw.
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1590,12 +1582,7 @@ public class IpSecService extends IIpSecService.Stub {
|
||||
dependencies.add(refcountedSpiRecord);
|
||||
SpiRecord spiRecord = refcountedSpiRecord.getResource();
|
||||
|
||||
try {
|
||||
createOrUpdateTransform(c, resourceId, spiRecord, socketRecord);
|
||||
} catch (ServiceSpecificException e) {
|
||||
// FIXME: get the error code and throw is at an IOException from Errno Exception
|
||||
return new IpSecTransformResponse(IpSecManager.Status.RESOURCE_UNAVAILABLE);
|
||||
}
|
||||
createOrUpdateTransform(c, resourceId, spiRecord, socketRecord);
|
||||
|
||||
// SA was created successfully, time to construct a record and lock it away
|
||||
userRecord.mTransformRecords.put(
|
||||
@@ -1642,23 +1629,15 @@ public class IpSecService extends IIpSecService.Stub {
|
||||
c.getMode() == IpSecTransform.MODE_TRANSPORT,
|
||||
"Transform mode was not Transport mode; cannot be applied to a socket");
|
||||
|
||||
try {
|
||||
mSrvConfig
|
||||
.getNetdInstance()
|
||||
.ipSecApplyTransportModeTransform(
|
||||
socket.getFileDescriptor(),
|
||||
resourceId,
|
||||
direction,
|
||||
c.getSourceAddress(),
|
||||
c.getDestinationAddress(),
|
||||
info.getSpiRecord().getSpi());
|
||||
} catch (ServiceSpecificException e) {
|
||||
if (e.errorCode == EINVAL) {
|
||||
throw new IllegalArgumentException(e.toString());
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
mSrvConfig
|
||||
.getNetdInstance()
|
||||
.ipSecApplyTransportModeTransform(
|
||||
socket.getFileDescriptor(),
|
||||
resourceId,
|
||||
direction,
|
||||
c.getSourceAddress(),
|
||||
c.getDestinationAddress(),
|
||||
info.getSpiRecord().getSpi());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1670,13 +1649,9 @@ public class IpSecService extends IIpSecService.Stub {
|
||||
@Override
|
||||
public synchronized void removeTransportModeTransforms(ParcelFileDescriptor socket)
|
||||
throws RemoteException {
|
||||
try {
|
||||
mSrvConfig
|
||||
.getNetdInstance()
|
||||
.ipSecRemoveTransportModeTransform(socket.getFileDescriptor());
|
||||
} catch (ServiceSpecificException e) {
|
||||
// FIXME: get the error code and throw is at an IOException from Errno Exception
|
||||
}
|
||||
mSrvConfig
|
||||
.getNetdInstance()
|
||||
.ipSecRemoveTransportModeTransform(socket.getFileDescriptor());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user