summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorBjorn Bringert <bringert@android.com>2009-05-28 14:48:32 +0100
committerBjorn Bringert <bringert@android.com>2009-05-29 09:06:44 +0100
commit9fc2e9c965c68d56a0caf812f7f6d38d15317063 (patch)
treead925b8780f3112c60206b15a17ec874f142b3a0 /core
parent607384d45fae5c9c2b21c96e4278665c8d7d3006 (diff)
downloadframeworks_base-9fc2e9c965c68d56a0caf812f7f6d38d15317063.zip
frameworks_base-9fc2e9c965c68d56a0caf812f7f6d38d15317063.tar.gz
frameworks_base-9fc2e9c965c68d56a0caf812f7f6d38d15317063.tar.bz2
MemoryFile constructor and native methods throw IOExceptions.
These native methods in android.os.MemoryFile throw IOException but their Java declarations did not include "throws IOException": native_open(),native_mmap(),native_read(),native_write(),native_pin() The MemoryFile(String,int) constructor calls native_open and native_mmap, but does not declare that it throws IOException. The other Java methods that call the native methods do actually declare that they throw IOException. This means that any code that created memory files could throw an IOException, without knowing about it. This changes adds "throws IOException" to the native methods and to the constructor. The constructor change changes the public API, but maintains binary compatibility. There is some precedent for making source incompatible source API changes for this sort of thing (see https://mondrian.corp.google.com/changelist/124214-p9). The change also makes the native methods static, which they seem to have been intended to be, as indicated by the second parameter to the native implementations being named "clazz". This requires changes to the Compatibility Test Suite to catch the exceptions. This is done in https://android-git.corp.google.com/g/2617 Unfortunately that change must be submitted together with this one in order not to break the build. Fixes http://b/issue?id=1881829
Diffstat (limited to 'core')
-rw-r--r--core/java/android/os/MemoryFile.java19
1 files changed, 10 insertions, 9 deletions
diff --git a/core/java/android/os/MemoryFile.java b/core/java/android/os/MemoryFile.java
index 76e4f47..2e4d9b1 100644
--- a/core/java/android/os/MemoryFile.java
+++ b/core/java/android/os/MemoryFile.java
@@ -37,15 +37,15 @@ public class MemoryFile
private static String TAG = "MemoryFile";
// returns fd
- private native int native_open(String name, int length);
+ private static native int native_open(String name, int length) throws IOException;
// returns memory address for ashmem region
- private native int native_mmap(int fd, int length);
- private native void native_close(int fd);
- private native int native_read(int fd, int address, byte[] buffer,
- int srcOffset, int destOffset, int count, boolean isUnpinned);
- private native void native_write(int fd, int address, byte[] buffer,
- int srcOffset, int destOffset, int count, boolean isUnpinned);
- private native void native_pin(int fd, boolean pin);
+ private static native int native_mmap(int fd, int length) throws IOException;
+ private static native void native_close(int fd);
+ private static native int native_read(int fd, int address, byte[] buffer,
+ int srcOffset, int destOffset, int count, boolean isUnpinned) throws IOException;
+ private static native void native_write(int fd, int address, byte[] buffer,
+ int srcOffset, int destOffset, int count, boolean isUnpinned) throws IOException;
+ private static native void native_pin(int fd, boolean pin) throws IOException;
private int mFD; // ashmem file descriptor
private int mAddress; // address of ashmem memory
@@ -57,8 +57,9 @@ public class MemoryFile
*
* @param name optional name for the file (can be null).
* @param length of the memory file in bytes.
+ * @throws IOException if the memory file could not be created.
*/
- public MemoryFile(String name, int length) {
+ public MemoryFile(String name, int length) throws IOException {
mLength = length;
mFD = native_open(name, length);
mAddress = native_mmap(mFD, length);