Here is what worked for me:
1) Open a MemoryFile object: mFile;
2) create a service to map it to ashem using mmap;
3) Return the native file descriptor (fd) to client that binds to your service using ParcelFileDescriptor pfd;
4) Create JNI for the client that takes the fd and map to ashes using mmap;
5) Create InputStream using this fd and now the client can read/write the same memory area using InputStream object.
This link shows how to map a MemoryFile to ashem. This link shows how to send native file descriptor (fd) to client through AIDL and ParcelFileDescriptor to client.
On the server side, you will need create:
1) A service & AIDL that passes native fd to client through ParcelFileDescriptor;
2) A JNI on the service side that does the mapping.
On the client:
1) Methods to Bind to service and then call service to get native fd;
2) A JNI that maps the fd to ashem.
The mapped memory region can then be read/write by the service & client.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…