From 031d4473639085411b619b41e6e00a6d96827677 Mon Sep 17 00:00:00 2001 From: Benedict Wong Date: Mon, 2 Apr 2018 18:12:34 -0700 Subject: [PATCH 1/2] Force creation of Socket upon Transform application This change forces Socket and DatagramSocket to populate the SocketImpl, ensuring that the socket file descriptor can be retrieved when applying Transport mode Transforms This is done by calling getSoLinger(), triggering a getImpl(), which triggers setImpl() if needed. Bug: 77491294 Test: Added tests in IpSecManagerTest, ran on walleye Merged-In: I40da08b031357710eb794e0f866aec5660c79594 Change-Id: I40da08b031357710eb794e0f866aec5660c79594 (cherry picked from commit d175a3d3a01cfdb5ab6d4e61d15950583f8006d6) --- .../java/android/net/IpSecManagerTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/net/java/android/net/IpSecManagerTest.java b/tests/net/java/android/net/IpSecManagerTest.java index a946e50585..88d47ba0f2 100644 --- a/tests/net/java/android/net/IpSecManagerTest.java +++ b/tests/net/java/android/net/IpSecManagerTest.java @@ -38,6 +38,7 @@ import android.system.Os; import com.android.server.IpSecService; import java.net.InetAddress; +import java.net.Socket; import java.net.UnknownHostException; import org.junit.Before; @@ -194,6 +195,33 @@ public class IpSecManagerTest { verify(mMockIpSecService).closeUdpEncapsulationSocket(DUMMY_RESOURCE_ID); } + @Test + public void testApplyTransportModeTransformEnsuresSocketCreation() throws Exception { + Socket socket = new Socket(); + IpSecConfig dummyConfig = new IpSecConfig(); + IpSecTransform dummyTransform = new IpSecTransform(null, dummyConfig); + + // Even if underlying SocketImpl is not initalized, this should force the init, and + // thereby succeed. + mIpSecManager.applyTransportModeTransform( + socket, IpSecManager.DIRECTION_IN, dummyTransform); + + // Check to make sure the FileDescriptor is non-null + assertNotNull(socket.getFileDescriptor$()); + } + + @Test + public void testRemoveTransportModeTransformsForcesSocketCreation() throws Exception { + Socket socket = new Socket(); + + // Even if underlying SocketImpl is not initalized, this should force the init, and + // thereby succeed. + mIpSecManager.removeTransportModeTransforms(socket); + + // Check to make sure the FileDescriptor is non-null + assertNotNull(socket.getFileDescriptor$()); + } + @Test public void testOpenEncapsulationSocketOnRandomPort() throws Exception { IpSecUdpEncapResponse udpEncapResp = From ab5f8652d31523ecd281c1a5693a90e934180425 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Mon, 9 Apr 2018 16:15:03 -0600 Subject: [PATCH 2/2] Disable roaming sanity checking. We've traced down all code paths where NetworkInfo.isRoaming() and NET_CAPABILITY_NOT_ROAMING can disagree, so we're only left with noise that happens from NetworkAgent race conditions when someone asks for a NetworkState between pending NetworkInfo and NetworkCapabilities updates. We can look at adding a way for a NetworkAgent to update these two objects atomically, but not for this release. Bug: 70174865 Test: builds, boots Change-Id: I830e1fc6dc922e9eb7f8c2698d75181e00aaf7fb --- core/java/android/net/NetworkState.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/java/android/net/NetworkState.java b/core/java/android/net/NetworkState.java index b00cb482e7..321f9718ee 100644 --- a/core/java/android/net/NetworkState.java +++ b/core/java/android/net/NetworkState.java @@ -26,6 +26,8 @@ import android.util.Slog; * @hide */ public class NetworkState implements Parcelable { + private static final boolean SANITY_CHECK_ROAMING = false; + public static final NetworkState EMPTY = new NetworkState(null, null, null, null, null, null); public final NetworkInfo networkInfo; @@ -47,7 +49,7 @@ public class NetworkState implements Parcelable { // This object is an atomic view of a network, so the various components // should always agree on roaming state. - if (networkInfo != null && networkCapabilities != null) { + if (SANITY_CHECK_ROAMING && networkInfo != null && networkCapabilities != null) { if (networkInfo.isRoaming() == networkCapabilities .hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING)) { Slog.wtf("NetworkState", "Roaming state disagreement between " + networkInfo