Move PlainDatagramSocketImpl away from JNI (part 1)

Rewrites all JNI methods in PlainDatagramSocketImpl apart from
socket{Get,Set}Option on top of IoBridge.

There are some differences comparing to JNI code:
bind:
  * We don't set setDefaultScopeID, since that's not necessary for
    Linux.
send:
  * OpenJDK sets sin6_flowinfo field, but this is against RFC3493 and is
    not used by the kernel. We don't set this field.
peek:
  * Temporary DatagramPacket object has zero length instead of one in
    original implementation. These is no need to have that one byte and
    has better performance by avoid allocating a buffer.
datagramSocketCreate:
  * We don't need to explicitly setsockopt IP_MULTICAST_ALL to 0, as
    this is default for AF_INET6 sockets and we always create sockets
    with AF_INET6 in Android libcore.
  * We also don't explicitly setsockopt IPV6_MULTICAST_HOPS, since this
    is to workaround a bug in old Linux kernels (< 2.4) and no longer
    relevant.

Also while rewriting, several behaviour changes from M were found and
the rewrite keeps the N behaviour:
send:
  * If sendto(2) sets errno as ECONNREFUSED, we now throw
    PortUnreachableException instead of ignoring, and if it set errno
    as ECONNRESET, we throw IOException instead of ignoring.
    In all the other cases, we throw IOException instead of
    SocketException.
recv/peek:
  * packet.address should only be updated if source address is
    different, and should be the same object if address is the same.

Test: CtsLibcoreTestCases
Bug: 28609551
Change-Id: I9a5c65cce8dee9695966012f8f2e3ddf9d84bae4
3 files changed