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)
This commit is contained in:
Benedict Wong
2018-04-02 18:12:34 -07:00
parent 65ef843176
commit 57ab3f648e

View File

@@ -337,6 +337,9 @@ public final class IpSecManager {
*/ */
public void applyTransportModeTransform(@NonNull Socket socket, public void applyTransportModeTransform(@NonNull Socket socket,
@PolicyDirection int direction, @NonNull IpSecTransform transform) throws IOException { @PolicyDirection int direction, @NonNull IpSecTransform transform) throws IOException {
// Ensure creation of FD. See b/77548890 for more details.
socket.getSoLinger();
applyTransportModeTransform(socket.getFileDescriptor$(), direction, transform); applyTransportModeTransform(socket.getFileDescriptor$(), direction, transform);
} }
@@ -441,6 +444,9 @@ public final class IpSecManager {
* @throws IOException indicating that the transform could not be removed from the socket * @throws IOException indicating that the transform could not be removed from the socket
*/ */
public void removeTransportModeTransforms(@NonNull Socket socket) throws IOException { public void removeTransportModeTransforms(@NonNull Socket socket) throws IOException {
// Ensure creation of FD. See b/77548890 for more details.
socket.getSoLinger();
removeTransportModeTransforms(socket.getFileDescriptor$()); removeTransportModeTransforms(socket.getFileDescriptor$());
} }