Merge "Replace hidden getFileDescriptor$()" am: 842319b819 am: 4b2d4e4e3b am: 9bb7ef7bd2

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1553966

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Iebc2b32fa7ed14b5326ec7649831fbc8e08b1e9d
This commit is contained in:
Chiachang Wang
2021-01-28 08:06:05 +00:00
committed by Automerger Merge Worker

View File

@@ -22,6 +22,7 @@ import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Build;
import android.os.Parcel;
import android.os.ParcelFileDescriptor;
import android.os.Parcelable;
import android.system.ErrnoException;
import android.system.Os;
@@ -381,7 +382,13 @@ public class Network implements Parcelable {
// 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.
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();
}
/**
@@ -393,7 +400,13 @@ public class Network implements Parcelable {
// 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.
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();
}
/**