Cannot Connect To Native Local Socket On Android 5.1
I have commad-line tool, which sends broadcast and wait result. Server code (error handling omitted): int makeAddr(const char* name, struct sockaddr_un* pAddr, socklen_t* pSock
Solution 1:
Use pipes instead of socket: O_RDWR on named pipes with poll()
Create pipe in java process:
mkfifo(cpath, 0);
chmod(cpath, S_IRWXU|S_IROTH|S_IRGRP);
Open pipe in native process:
int serverFd = open(PIPE_NAME, O_RDONLY | O_NONBLOCK);
pollfd pollFd = {0};
pollFd.fd = serverFd.get();
pollFd.events = POLLIN | POLLRDHUP;
//send command
....
for(;;)
{
int pollResult = poll(&pollFd, 1, timeout);
Solution 2:
In my experience on Android 10, abstract namespace unix domain sockets and unnamed pipes work within the same application, but not across different apps. I implemented both the client and server natively, though.
For named pipes, you have to create the file somewhere where you have write permissions. Basically your app's data folder.
For inter-process communication, you can attempt sending file descriptors from one process to another to grant access according to this, but I'm not sure how it works. I ended up using network sockets for this.
Post a Comment for "Cannot Connect To Native Local Socket On Android 5.1"