Merge "ParcelFileDescriptor: fix various ownership mistakes."
am: 8d7976a37e
Change-Id: I4a6b274fcbb09ab52242f00a85630e91c1d87a5a
This commit is contained in:
@@ -55,6 +55,7 @@ import java.io.FileNotFoundException;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InterruptedIOException;
|
import java.io.InterruptedIOException;
|
||||||
|
import java.io.UncheckedIOException;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
@@ -397,26 +398,41 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
|
|||||||
* @param socket The Socket whose FileDescriptor is used to create
|
* @param socket The Socket whose FileDescriptor is used to create
|
||||||
* a new ParcelFileDescriptor.
|
* a new ParcelFileDescriptor.
|
||||||
*
|
*
|
||||||
* @return A new ParcelFileDescriptor with the FileDescriptor of the
|
* @return A new ParcelFileDescriptor with a duped copy of the
|
||||||
* specified Socket.
|
* FileDescriptor of the specified Socket.
|
||||||
|
*
|
||||||
|
* @throws UncheckedIOException if {@link #dup(FileDescriptor)} throws IOException.
|
||||||
*/
|
*/
|
||||||
public static ParcelFileDescriptor fromSocket(Socket socket) {
|
public static ParcelFileDescriptor fromSocket(Socket socket) {
|
||||||
FileDescriptor fd = socket.getFileDescriptor$();
|
FileDescriptor fd = socket.getFileDescriptor$();
|
||||||
return fd != null ? new ParcelFileDescriptor(fd) : null;
|
try {
|
||||||
|
return fd != null ? ParcelFileDescriptor.dup(fd) : null;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new UncheckedIOException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new ParcelFileDescriptor from the specified DatagramSocket.
|
* Create a new ParcelFileDescriptor from the specified DatagramSocket. The
|
||||||
|
* new ParcelFileDescriptor holds a dup of the original FileDescriptor in
|
||||||
|
* the DatagramSocket, so you must still close the DatagramSocket as well
|
||||||
|
* as the new ParcelFileDescriptor.
|
||||||
*
|
*
|
||||||
* @param datagramSocket The DatagramSocket whose FileDescriptor is used
|
* @param datagramSocket The DatagramSocket whose FileDescriptor is used
|
||||||
* to create a new ParcelFileDescriptor.
|
* to create a new ParcelFileDescriptor.
|
||||||
*
|
*
|
||||||
* @return A new ParcelFileDescriptor with the FileDescriptor of the
|
* @return A new ParcelFileDescriptor with a duped copy of the
|
||||||
* specified DatagramSocket.
|
* FileDescriptor of the specified Socket.
|
||||||
|
*
|
||||||
|
* @throws UncheckedIOException if {@link #dup(FileDescriptor)} throws IOException.
|
||||||
*/
|
*/
|
||||||
public static ParcelFileDescriptor fromDatagramSocket(DatagramSocket datagramSocket) {
|
public static ParcelFileDescriptor fromDatagramSocket(DatagramSocket datagramSocket) {
|
||||||
FileDescriptor fd = datagramSocket.getFileDescriptor$();
|
FileDescriptor fd = datagramSocket.getFileDescriptor$();
|
||||||
return fd != null ? new ParcelFileDescriptor(fd) : null;
|
try {
|
||||||
|
return fd != null ? ParcelFileDescriptor.dup(fd) : null;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new UncheckedIOException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -546,7 +562,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
|
|||||||
}
|
}
|
||||||
file.deactivate();
|
file.deactivate();
|
||||||
FileDescriptor fd = file.getFileDescriptor();
|
FileDescriptor fd = file.getFileDescriptor();
|
||||||
return fd != null ? new ParcelFileDescriptor(fd) : null;
|
return fd != null ? ParcelFileDescriptor.dup(fd) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user