Do not make IkeSocket SOCK_NONBLOCK to save CPU utilization

IKE has high CPU utilization because IkeSocket is using a while(true)
poll loop and do non-blocking read from the socket. It means the reading
thread keeps entering the while loop. This CL makes the socket blocking
so that the reading thread will wait for receiving bytes before
re-entering the while loop.

For FrameworksIkeTests. this CL decreases the CPU utilization from 450%
to 100% and decreases the tests running time from 4 minutes to 30
seconds.

For more context, previously, to use PacketReader for receiving packets,
IKE socket MUST be explicitly set SOCK_NONBLOCK. Later we switched to
use a poll loop instead of PacketReader because FD_EVENT notifications
which triggers reading packets were sometimes not fired. However, we
forgot to revert the statement to set socket SOCK_NONBLOCK.

Bug: 173566036
Test: atest FrameworksIkeTests, CtsIkeTestCases
Change-Id: I902b53168935d7d1a822900a37249f00d0af1c4c
diff --git a/src/java/com/android/internal/net/ipsec/ike/IkeUdp4Socket.java b/src/java/com/android/internal/net/ipsec/ike/IkeUdp4Socket.java
index 3f26fd9..44ccac0 100644
--- a/src/java/com/android/internal/net/ipsec/ike/IkeUdp4Socket.java
+++ b/src/java/com/android/internal/net/ipsec/ike/IkeUdp4Socket.java
@@ -17,10 +17,8 @@
 package com.android.internal.net.ipsec.ike;
 
 import static android.system.OsConstants.AF_INET;
-import static android.system.OsConstants.F_SETFL;
 import static android.system.OsConstants.IPPROTO_UDP;
 import static android.system.OsConstants.SOCK_DGRAM;
-import static android.system.OsConstants.SOCK_NONBLOCK;
 
 import android.net.InetAddresses;
 import android.net.Network;
@@ -71,9 +69,6 @@
         if (ikeSocket == null) {
             FileDescriptor sock = Os.socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
             Os.bind(sock, INADDR_ANY, 0);
-
-            // {@link PacketReader} requires non-blocking I/O access. Set SOCK_NONBLOCK here.
-            Os.fcntlInt(sock, F_SETFL, SOCK_DGRAM | SOCK_NONBLOCK);
             network.bindSocket(sock);
 
             ikeSocket = new IkeUdp4Socket(sock, network, handler);
diff --git a/src/java/com/android/internal/net/ipsec/ike/IkeUdp6Socket.java b/src/java/com/android/internal/net/ipsec/ike/IkeUdp6Socket.java
index 647583d..c195156 100644
--- a/src/java/com/android/internal/net/ipsec/ike/IkeUdp6Socket.java
+++ b/src/java/com/android/internal/net/ipsec/ike/IkeUdp6Socket.java
@@ -17,10 +17,8 @@
 package com.android.internal.net.ipsec.ike;
 
 import static android.system.OsConstants.AF_INET6;
-import static android.system.OsConstants.F_SETFL;
 import static android.system.OsConstants.IPPROTO_UDP;
 import static android.system.OsConstants.SOCK_DGRAM;
-import static android.system.OsConstants.SOCK_NONBLOCK;
 
 import android.net.InetAddresses;
 import android.net.Network;
@@ -84,9 +82,6 @@
             throws ErrnoException, IOException {
         FileDescriptor sock = Os.socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
         Os.bind(sock, INADDR_ANY, 0);
-
-        // {@link PacketReader} requires non-blocking I/O access. Set SOCK_NONBLOCK here.
-        Os.fcntlInt(sock, F_SETFL, SOCK_DGRAM | SOCK_NONBLOCK);
         network.bindSocket(sock);
 
         return sock;
diff --git a/src/java/com/android/internal/net/ipsec/ike/IkeUdpEncapSocket.java b/src/java/com/android/internal/net/ipsec/ike/IkeUdpEncapSocket.java
index 11bb934..5e94694 100644
--- a/src/java/com/android/internal/net/ipsec/ike/IkeUdpEncapSocket.java
+++ b/src/java/com/android/internal/net/ipsec/ike/IkeUdpEncapSocket.java
@@ -17,9 +17,6 @@
 package com.android.internal.net.ipsec.ike;
 
 import static android.net.ipsec.ike.IkeManager.getIkeLog;
-import static android.system.OsConstants.F_SETFL;
-import static android.system.OsConstants.SOCK_DGRAM;
-import static android.system.OsConstants.SOCK_NONBLOCK;
 
 import android.net.IpSecManager;
 import android.net.IpSecManager.ResourceUnavailableException;
@@ -91,9 +88,6 @@
         if (ikeSocket == null) {
             UdpEncapsulationSocket udpEncapSocket = ipsecManager.openUdpEncapsulationSocket();
             FileDescriptor fd = udpEncapSocket.getFileDescriptor();
-
-            // {@link PacketReader} requires non-blocking I/O access. Set SOCK_NONBLOCK here.
-            Os.fcntlInt(fd, F_SETFL, SOCK_DGRAM | SOCK_NONBLOCK);
             network.bindSocket(fd);
 
             ikeSocket = new IkeUdpEncapSocket(udpEncapSocket, network, new Handler(looper));