Problem: How to read /dev/diag port data directly from a device that have rooted shell. Code:
fd = open("/dev/diag", O_RDWR | O_LARGEFILE | O_NONBLOCK);
if (fd < 0) {
perror("open diag dev");
return -8002;
}
Working solution with rooted adb shell and c executable:
- Make an executable of c code.
- Create new user in android.
- Make executable owner is this new user id with 'su shell'.
- Make /dev/diag port owner is this new user id with 'su shell'.
- Run executable without su permissions but in new user shell. I am able to get the data from /dev/diag port everytime after just one time procedure written above. So I do not need the rooted shell again to run my executable and read data from /dev/diag port.
Non-working solution with rooted adb shell and android application:
- Install an apk in your device that has UI to call the required function on JNI side to start reading data from the port.
- Find the user id of the installed application. I found it in data/system/packages.list file.
- Make /dev/diag port owner is this new user id with 'su shell'.
- Call the required function in the application that further try to open /dev/diag port. The dev/diag port is not opened by code and retured -8002.
I don't have enough linux knowledge but have a little idea that if I have rooted shell then I can surely give my android application an access on /dev/diag port.
Please help me in this. I will be really thankful to you.