Changes to PFD based on API review
Removed boolean param to ask for exception on detached fd. Use a subclass of IOException instead. Bug: 10461576 Change-Id: If7db16120297edcdb7d5d5905ed453003be0e38e
This commit is contained in:
@@ -18294,7 +18294,7 @@ package android.os {
|
||||
ctor public ParcelFileDescriptor(android.os.ParcelFileDescriptor);
|
||||
method public static android.os.ParcelFileDescriptor adoptFd(int);
|
||||
method public boolean canDetectErrors();
|
||||
method public void checkError(boolean) throws java.io.IOException;
|
||||
method public void checkError() throws java.io.IOException;
|
||||
method public void close() throws java.io.IOException;
|
||||
method public void closeWithError(java.lang.String) throws java.io.IOException;
|
||||
method public static android.os.ParcelFileDescriptor[] createPipe() throws java.io.IOException;
|
||||
@@ -18333,8 +18333,12 @@ package android.os {
|
||||
ctor public ParcelFileDescriptor.AutoCloseOutputStream(android.os.ParcelFileDescriptor);
|
||||
}
|
||||
|
||||
public static class ParcelFileDescriptor.FileDescriptorDetachedException extends java.io.IOException {
|
||||
ctor public ParcelFileDescriptor.FileDescriptorDetachedException();
|
||||
}
|
||||
|
||||
public static abstract interface ParcelFileDescriptor.OnCloseListener {
|
||||
method public abstract void onClose(java.io.IOException, boolean);
|
||||
method public abstract void onClose(java.io.IOException);
|
||||
}
|
||||
|
||||
public class ParcelFormatException extends java.lang.RuntimeException {
|
||||
|
||||
@@ -80,7 +80,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
|
||||
private byte[] mStatusBuf;
|
||||
|
||||
/**
|
||||
* Status read by {@link #checkError(boolean)}, or null if not read yet.
|
||||
* Status read by {@link #checkError()}, or null if not read yet.
|
||||
*/
|
||||
private Status mStatus;
|
||||
|
||||
@@ -371,7 +371,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
|
||||
* <p>
|
||||
* The write end has the ability to deliver an error message through
|
||||
* {@link #closeWithError(String)} which can be handled by the read end
|
||||
* calling {@link #checkError(boolean)}, usually after detecting an EOF.
|
||||
* calling {@link #checkError()}, usually after detecting an EOF.
|
||||
* This can also be used to detect remote crashes.
|
||||
*/
|
||||
public static ParcelFileDescriptor[] createReliablePipe() throws IOException {
|
||||
@@ -409,7 +409,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
|
||||
* <p>
|
||||
* Both ends have the ability to deliver an error message through
|
||||
* {@link #closeWithError(String)} which can be detected by the other end
|
||||
* calling {@link #checkError(boolean)}, usually after detecting an EOF.
|
||||
* calling {@link #checkError()}, usually after detecting an EOF.
|
||||
* This can also be used to detect remote crashes.
|
||||
*/
|
||||
public static ParcelFileDescriptor[] createReliableSocketPair() throws IOException {
|
||||
@@ -685,7 +685,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
|
||||
* Indicates if this ParcelFileDescriptor can communicate and detect remote
|
||||
* errors/crashes.
|
||||
*
|
||||
* @see #checkError(boolean)
|
||||
* @see #checkError()
|
||||
*/
|
||||
public boolean canDetectErrors() {
|
||||
if (mWrapped != null) {
|
||||
@@ -703,17 +703,16 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
|
||||
* If this ParcelFileDescriptor is unable to detect remote errors, it will
|
||||
* return silently.
|
||||
*
|
||||
* @param throwIfDetached requests that an exception be thrown if the remote
|
||||
* side called {@link #detachFd()}. Once detached, the remote
|
||||
* @throws IOException for normal errors.
|
||||
* @throws FileDescriptorDetachedException
|
||||
* if the remote side called {@link #detachFd()}. Once detached, the remote
|
||||
* side is unable to communicate any errors through
|
||||
* {@link #closeWithError(String)}. An application may pass true
|
||||
* if it needs a stronger guarantee that the stream was closed
|
||||
* normally and was not merely detached.
|
||||
* {@link #closeWithError(String)}.
|
||||
* @see #canDetectErrors()
|
||||
*/
|
||||
public void checkError(boolean throwIfDetached) throws IOException {
|
||||
public void checkError() throws IOException {
|
||||
if (mWrapped != null) {
|
||||
mWrapped.checkError(throwIfDetached);
|
||||
mWrapped.checkError();
|
||||
} else {
|
||||
if (mStatus == null) {
|
||||
if (mCommFd == null) {
|
||||
@@ -726,8 +725,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
|
||||
mStatus = readCommStatus(mCommFd, getOrCreateStatusBuffer());
|
||||
}
|
||||
|
||||
if (mStatus == null || mStatus.status == Status.OK
|
||||
|| (mStatus.status == Status.DETACHED && !throwIfDetached)) {
|
||||
if (mStatus == null || mStatus.status == Status.OK) {
|
||||
// No status yet, or everything is peachy!
|
||||
return;
|
||||
} else {
|
||||
@@ -868,13 +866,26 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
|
||||
* attached has been closed.
|
||||
*
|
||||
* @param e error state, or {@code null} if closed cleanly.
|
||||
* @param fromDetach indicates if close event was result of
|
||||
* {@link ParcelFileDescriptor#detachFd()}. After detach the
|
||||
* remote side may continue reading/writing to the underlying
|
||||
* {@link FileDescriptor}, but they can no longer deliver
|
||||
* reliable close/error events.
|
||||
* If the close event was the result of
|
||||
* {@link ParcelFileDescriptor#detachFd()}, this will be a
|
||||
* {@link FileDescriptorDetachedException}. After detach the
|
||||
* remote side may continue reading/writing to the underlying
|
||||
* {@link FileDescriptor}, but they can no longer deliver
|
||||
* reliable close/error events.
|
||||
*/
|
||||
public void onClose(IOException e, boolean fromDetach);
|
||||
public void onClose(IOException e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception that indicates that the file descriptor was detached.
|
||||
*/
|
||||
public static class FileDescriptorDetachedException extends IOException {
|
||||
|
||||
private static final long serialVersionUID = 0xDe7ac4edFdL;
|
||||
|
||||
public FileDescriptorDetachedException() {
|
||||
super("Remote side is detached");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -917,7 +928,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
|
||||
case ERROR:
|
||||
return new IOException("Remote error: " + msg);
|
||||
case DETACHED:
|
||||
return new IOException("Remote side is detached");
|
||||
return new FileDescriptorDetachedException();
|
||||
case LEAKED:
|
||||
return new IOException("Remote side was leaked");
|
||||
default:
|
||||
@@ -942,13 +953,7 @@ public class ParcelFileDescriptor implements Parcelable, Closeable {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
final Status s = (Status) msg.obj;
|
||||
if (s.status == Status.DETACHED) {
|
||||
listener.onClose(null, true);
|
||||
} else if (s.status == Status.OK) {
|
||||
listener.onClose(null, false);
|
||||
} else {
|
||||
listener.onClose(s.asIOException(), false);
|
||||
}
|
||||
listener.onClose(s != null ? s.asIOException() : null);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user