compat/src/main/java/androidx/core/net/TrafficStatsCompat.java
public static void tagDatagramSocket(@NonNull DatagramSocket socket) throws SocketException {
        if (Build.VERSION.SDK_INT >= 24) {
            TrafficStats.tagDatagramSocket(socket);
        } else {
            final ParcelFileDescriptor pfd = ParcelFileDescriptor.fromDatagramSocket(socket);
            TrafficStats.tagSocket(new DatagramSocketWrapper(socket, pfd.getFileDescriptor()));
            // The developer is still using the FD, so we need to detach it to
            // prevent the PFD finalizer from closing it in their face. We had to
            // wait until after the tagging call above, since detaching clears out
            // the getFileDescriptor() result which tagging depends on.
            pfd.detachFd();
        }
    }
/**
     * Tag the given {@link DatagramSocket} with any statistics parameters
     * active for the current thread. Subsequent calls always replace any
     * existing parameters. When finished, call
     * {@link #untagDatagramSocket(DatagramSocket)} to remove statistics
     * parameters.
     *
     * @see #setThreadStatsTag(int)
     */
Tag the given  DatagramSocket with any statistics parameters
active for the current thread. Subsequent calls always replace any
existing parameters. When finished, call
#untagDatagramSocket(DatagramSocket) to remove statistics
parameters.


Tag the given DatagramSocket with any statistics parameters active for the current thread . Subsequent calls always replace any existing parameters . When finished call #untagDatagramSocket ( DatagramSocket ) to remove statistics parameters .
public static void tagDatagramSocket(@NonNull DatagramSocket socket) throws SocketException {
        if (Build.VERSION.SDK_INT >= 24) {
            TrafficStats.tagDatagramSocket(socket);
        } else {
            final ParcelFileDescriptor pfd = ParcelFileDescriptor.fromDatagramSocket(socket);
            TrafficStats.tagSocket(new DatagramSocketWrapper(socket, pfd.getFileDescriptor()));
            pfd.detachFd();
        }
    }
public static void tagDatagramSocket ( @ NonNull DatagramSocket socket ) throws SocketException { if ( Build . VERSION . SDK_INT >= 24 ) { TrafficStats . tagDatagramSocket ( socket ) ; } else { final ParcelFileDescriptor pfd = ParcelFileDescriptor . fromDatagramSocket ( socket ) ; TrafficStats . tagSocket ( new DatagramSocketWrapper ( socket , pfd . getFileDescriptor ( ) ) ) ; pfd . detachFd ( ) ; } }
Tag the given {@link DatagramSocket} with any statistics parameters
 active for the current thread.
Tag the given { @link DatagramSocket } with any statistics parameters active for the current thread .
// The developer is still using the FD, so we need to detach it to // prevent the PFD finalizer from closing it in their face. We had to // wait until after the tagging call above, since detaching clears out // the getFileDescriptor() result which tagging depends on.