Merge change 4471

* changes:
  MemoryFile.isMemoryFile was internally determining the length of the ashmem region. This is actually useful information to have, so expose that more directly.
This commit is contained in:
Android (Google) Code Review
2009-06-17 14:04:35 -07:00
2 changed files with 21 additions and 8 deletions

View File

@@ -52,7 +52,7 @@ public class MemoryFile
private static native void native_write(FileDescriptor fd, int address, byte[] buffer,
int srcOffset, int destOffset, int count, boolean isUnpinned) throws IOException;
private static native void native_pin(FileDescriptor fd, boolean pin) throws IOException;
private static native boolean native_is_ashmem_region(FileDescriptor fd) throws IOException;
private static native int native_get_mapped_size(FileDescriptor fd) throws IOException;
private FileDescriptor mFD; // ashmem file descriptor
private int mAddress; // address of ashmem memory
@@ -300,7 +300,20 @@ public class MemoryFile
* @hide
*/
public static boolean isMemoryFile(FileDescriptor fd) throws IOException {
return native_is_ashmem_region(fd);
return (native_get_mapped_size(fd) >= 0);
}
/**
* Returns the size of the memory file, rounded up to a page boundary, that
* the file descriptor refers to, or -1 if the file descriptor does not
* refer to a memory file.
*
* @throws IOException If <code>fd</code> is not a valid file descriptor.
*
* @hide
*/
public static int getMappedSize(FileDescriptor fd) throws IOException {
return native_get_mapped_size(fd);
}
/**

View File

@@ -118,7 +118,7 @@ static void android_os_MemoryFile_pin(JNIEnv* env, jobject clazz, jobject fileDe
}
}
static jboolean android_os_MemoryFile_is_ashmem_region(JNIEnv* env, jobject clazz,
static jint android_os_MemoryFile_get_mapped_size(JNIEnv* env, jobject clazz,
jobject fileDescriptor) {
int fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
// Use ASHMEM_GET_SIZE to find out if the fd refers to an ashmem region.
@@ -129,13 +129,13 @@ static jboolean android_os_MemoryFile_is_ashmem_region(JNIEnv* env, jobject claz
if (errno == ENOTTY) {
// ENOTTY means that the ioctl does not apply to this object,
// i.e., it is not an ashmem region.
return JNI_FALSE;
return (jint) -1;
}
// Some other error, throw exception
jniThrowIOException(env, errno);
return JNI_FALSE;
return (jint) -1;
}
return JNI_TRUE;
return (jint) result;
}
static const JNINativeMethod methods[] = {
@@ -146,8 +146,8 @@ static const JNINativeMethod methods[] = {
{"native_read", "(Ljava/io/FileDescriptor;I[BIIIZ)I", (void*)android_os_MemoryFile_read},
{"native_write", "(Ljava/io/FileDescriptor;I[BIIIZ)V", (void*)android_os_MemoryFile_write},
{"native_pin", "(Ljava/io/FileDescriptor;Z)V", (void*)android_os_MemoryFile_pin},
{"native_is_ashmem_region", "(Ljava/io/FileDescriptor;)Z",
(void*)android_os_MemoryFile_is_ashmem_region}
{"native_get_mapped_size", "(Ljava/io/FileDescriptor;)I",
(void*)android_os_MemoryFile_get_mapped_size}
};
static const char* const kClassPathName = "android/os/MemoryFile";