public AshmemFile(ParcelFileDescriptor pfd, int length, int mode) throws IOException, NullPointerException, IllegalArgumentException { FileDescriptor fd = pfd.getFileDescriptor(); if (fd == null) { throw new NullPointerException("File descriptor is null."); } if (!isMemoryFile(fd)) { throw new IllegalArgumentException("Not a memory file."); } mLength = length; mFD = fd; mPFD = pfd; if (Build.VERSION.SDK_INT < 21) { mAddressInt = native_mmap_int(mFD, length, mode); } else { mAddressLong = native_mmap_1ong(mFD, length, mode); } }