Merge "Replace hidden getFileDescriptor$()"
This commit is contained in:
@@ -21,6 +21,7 @@ import android.annotation.SystemApi;
|
|||||||
import android.compat.annotation.UnsupportedAppUsage;
|
import android.compat.annotation.UnsupportedAppUsage;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.system.ErrnoException;
|
import android.system.ErrnoException;
|
||||||
import android.system.Os;
|
import android.system.Os;
|
||||||
@@ -380,7 +381,13 @@ public class Network implements Parcelable {
|
|||||||
// Query a property of the underlying socket to ensure that the socket's file descriptor
|
// Query a property of the underlying socket to ensure that the socket's file descriptor
|
||||||
// exists, is available to bind to a network and is not closed.
|
// exists, is available to bind to a network and is not closed.
|
||||||
socket.getReuseAddress();
|
socket.getReuseAddress();
|
||||||
bindSocket(socket.getFileDescriptor$());
|
final ParcelFileDescriptor pfd = ParcelFileDescriptor.fromDatagramSocket(socket);
|
||||||
|
bindSocket(pfd.getFileDescriptor());
|
||||||
|
// ParcelFileDescriptor.fromSocket() creates a dup of the original fd. The original and the
|
||||||
|
// dup share the underlying socket in the kernel. The socket is never truly closed until the
|
||||||
|
// last fd pointing to the socket being closed. So close the dup one after binding the
|
||||||
|
// socket to control the lifetime of the dup fd.
|
||||||
|
pfd.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -392,7 +399,13 @@ public class Network implements Parcelable {
|
|||||||
// Query a property of the underlying socket to ensure that the socket's file descriptor
|
// Query a property of the underlying socket to ensure that the socket's file descriptor
|
||||||
// exists, is available to bind to a network and is not closed.
|
// exists, is available to bind to a network and is not closed.
|
||||||
socket.getReuseAddress();
|
socket.getReuseAddress();
|
||||||
bindSocket(socket.getFileDescriptor$());
|
final ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket);
|
||||||
|
bindSocket(pfd.getFileDescriptor());
|
||||||
|
// ParcelFileDescriptor.fromSocket() creates a dup of the original fd. The original and the
|
||||||
|
// dup share the underlying socket in the kernel. The socket is never truly closed until the
|
||||||
|
// last fd pointing to the socket being closed. So close the dup one after binding the
|
||||||
|
// socket to control the lifetime of the dup fd.
|
||||||
|
pfd.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user