Backport ParcelFileDescriptor.createPipe() from master.
This allows content providers to expose arbitraty data through the ContentResolver open* APIs. Change-Id: I408a0b7cee9cdba5654a962098386c012d6b3549
This commit is contained in:
@@ -126818,6 +126818,19 @@
|
||||
<exception name="IOException" type="java.io.IOException">
|
||||
</exception>
|
||||
</method>
|
||||
<method name="createPipe"
|
||||
return="android.os.ParcelFileDescriptor[]"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="true"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<exception name="IOException" type="java.io.IOException">
|
||||
</exception>
|
||||
</method>
|
||||
<method name="describeContents"
|
||||
return="int"
|
||||
abstract="false"
|
||||
|
||||
@@ -133,6 +133,25 @@ public class ParcelFileDescriptor implements Parcelable {
|
||||
// Extracts the file descriptor from the specified socket and returns it untouched
|
||||
private static native FileDescriptor getFileDescriptorFromSocket(Socket socket);
|
||||
|
||||
/**
|
||||
* Create two ParcelFileDescriptors structured as a data pipe. The first
|
||||
* ParcelFileDescriptor in the returned array is the read side; the second
|
||||
* is the write side.
|
||||
*/
|
||||
public static ParcelFileDescriptor[] createPipe() throws IOException {
|
||||
FileDescriptor[] fds = new FileDescriptor[2];
|
||||
int res = createPipeNative(fds);
|
||||
if (res == 0) {
|
||||
ParcelFileDescriptor[] pfds = new ParcelFileDescriptor[2];
|
||||
pfds[0] = new ParcelFileDescriptor(fds[0]);
|
||||
pfds[1] = new ParcelFileDescriptor(fds[1]);
|
||||
return pfds;
|
||||
}
|
||||
throw new IOException("Unable to create pipe: errno=" + -res);
|
||||
}
|
||||
|
||||
private static native int createPipeNative(FileDescriptor[] outFds);
|
||||
|
||||
/**
|
||||
* Retrieve the actual FileDescriptor associated with this object.
|
||||
*
|
||||
|
||||
@@ -66,6 +66,26 @@ static jobject android_os_ParcelFileDescriptor_getFileDescriptorFromSocket(JNIEn
|
||||
return fileDescriptorClone;
|
||||
}
|
||||
|
||||
static int android_os_ParcelFileDescriptor_createPipeNative(JNIEnv* env,
|
||||
jobject clazz, jobjectArray outFds)
|
||||
{
|
||||
int fds[2];
|
||||
if (pipe(fds) < 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
for (int i=0; i<2; i++) {
|
||||
jobject fdObj = env->NewObject(gFileDescriptorOffsets.mClass,
|
||||
gFileDescriptorOffsets.mConstructor);
|
||||
if (fdObj != NULL) {
|
||||
env->SetIntField(fdObj, gFileDescriptorOffsets.mDescriptor, fds[i]);
|
||||
}
|
||||
env->SetObjectArrayElement(outFds, i, fdObj);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static jint getFd(JNIEnv* env, jobject clazz)
|
||||
{
|
||||
jobject descriptor = env->GetObjectField(clazz, gParcelFileDescriptorOffsets.mFileDescriptor);
|
||||
@@ -109,6 +129,8 @@ static jlong android_os_ParcelFileDescriptor_seekTo(JNIEnv* env,
|
||||
static const JNINativeMethod gParcelFileDescriptorMethods[] = {
|
||||
{"getFileDescriptorFromSocket", "(Ljava/net/Socket;)Ljava/io/FileDescriptor;",
|
||||
(void*)android_os_ParcelFileDescriptor_getFileDescriptorFromSocket},
|
||||
{"createPipeNative", "([Ljava/io/FileDescriptor;)I",
|
||||
(void*)android_os_ParcelFileDescriptor_createPipeNative},
|
||||
{"getStatSize", "()J",
|
||||
(void*)android_os_ParcelFileDescriptor_getStatSize},
|
||||
{"seekTo", "(J)J",
|
||||
|
||||
Reference in New Issue
Block a user