Merge "Throw IAE when Network's LinkProperties is null" am: 5345fa1144
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2101892 Change-Id: I3fbe53867df490d23703a681ae3fc99d33c2b9ea Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -817,10 +817,10 @@ public class IpSecManager {
|
|||||||
* </ol>
|
* </ol>
|
||||||
*
|
*
|
||||||
* @param underlyingNetwork the new {@link Network} that will carry traffic for this tunnel.
|
* @param underlyingNetwork the new {@link Network} that will carry traffic for this tunnel.
|
||||||
* This network MUST never be the network exposing this IpSecTunnelInterface, otherwise
|
* This network MUST be a functional {@link Network} with valid {@link LinkProperties},
|
||||||
* this method will throw an {@link IllegalArgumentException}. If the
|
* and MUST never be the network exposing this IpSecTunnelInterface, otherwise this
|
||||||
* IpSecTunnelInterface is later added to this network, all outbound traffic will be
|
* method will throw an {@link IllegalArgumentException}. If the IpSecTunnelInterface is
|
||||||
* blackholed.
|
* later added to this network, all outbound traffic will be blackholed.
|
||||||
*/
|
*/
|
||||||
// TODO: b/169171001 Update the documentation when transform migration is supported.
|
// TODO: b/169171001 Update the documentation when transform migration is supported.
|
||||||
// The purpose of making updating network and applying transforms separate is to leave open
|
// The purpose of making updating network and applying transforms separate is to leave open
|
||||||
@@ -962,7 +962,6 @@ public class IpSecManager {
|
|||||||
* IP header and IPsec Header on all inbound traffic).
|
* IP header and IPsec Header on all inbound traffic).
|
||||||
* <p>Applications should probably not use this API directly.
|
* <p>Applications should probably not use this API directly.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @param tunnel The {@link IpSecManager#IpSecTunnelInterface} that will use the supplied
|
* @param tunnel The {@link IpSecManager#IpSecTunnelInterface} that will use the supplied
|
||||||
* transform.
|
* transform.
|
||||||
* @param direction the direction, {@link DIRECTION_OUT} or {@link #DIRECTION_IN} in which
|
* @param direction the direction, {@link DIRECTION_OUT} or {@link #DIRECTION_IN} in which
|
||||||
|
|||||||
@@ -1452,6 +1452,11 @@ public class IpSecService extends IIpSecService.Stub {
|
|||||||
final ConnectivityManager connectivityManager =
|
final ConnectivityManager connectivityManager =
|
||||||
mContext.getSystemService(ConnectivityManager.class);
|
mContext.getSystemService(ConnectivityManager.class);
|
||||||
final LinkProperties lp = connectivityManager.getLinkProperties(underlyingNetwork);
|
final LinkProperties lp = connectivityManager.getLinkProperties(underlyingNetwork);
|
||||||
|
if (lp == null) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"LinkProperties is null. The underlyingNetwork may not be functional");
|
||||||
|
}
|
||||||
|
|
||||||
if (tunnelInterfaceInfo.getInterfaceName().equals(lp.getInterfaceName())) {
|
if (tunnelInterfaceInfo.getInterfaceName().equals(lp.getInterfaceName())) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Underlying network cannot be the network being exposed by this tunnel");
|
"Underlying network cannot be the network being exposed by this tunnel");
|
||||||
|
|||||||
@@ -782,6 +782,23 @@ public class IpSecServiceParameterizedTest {
|
|||||||
assertEquals(newFakeNetwork, tunnelInterfaceInfo.getUnderlyingNetwork());
|
assertEquals(newFakeNetwork, tunnelInterfaceInfo.getUnderlyingNetwork());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetNetworkForTunnelInterfaceFailsForNullLp() throws Exception {
|
||||||
|
final IpSecTunnelInterfaceResponse createTunnelResp =
|
||||||
|
createAndValidateTunnel(mSourceAddr, mDestinationAddr, BLESSED_PACKAGE);
|
||||||
|
final Network newFakeNetwork = new Network(1000);
|
||||||
|
final int tunnelIfaceResourceId = createTunnelResp.resourceId;
|
||||||
|
|
||||||
|
try {
|
||||||
|
mIpSecService.setNetworkForTunnelInterface(
|
||||||
|
tunnelIfaceResourceId, newFakeNetwork, BLESSED_PACKAGE);
|
||||||
|
fail(
|
||||||
|
"Expected an IllegalArgumentException for underlying network with null"
|
||||||
|
+ " LinkProperties");
|
||||||
|
} catch (IllegalArgumentException expected) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetNetworkForTunnelInterfaceFailsForInvalidResourceId() throws Exception {
|
public void testSetNetworkForTunnelInterfaceFailsForInvalidResourceId() throws Exception {
|
||||||
final IpSecTunnelInterfaceResponse createTunnelResp =
|
final IpSecTunnelInterfaceResponse createTunnelResp =
|
||||||
|
|||||||
Reference in New Issue
Block a user