I am trying to create a ServerSocket on a port below 1024.
Obviously, this restriction is limited only by root permissions.
But I'm afraid to get the correct permissions for my application.
I use this code, for example, to check if I have root access (or starting a dialog)
But it still does not allow me to work with ServerSocket.
AFAIK, a process created using the SU command has root access, not my application. How to root access my own process?
public stat
ic boolean getRoot() {
try {
Process p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("echo \"Do I have root?\" >/system/sd/temporary.txt\n");
os.writeBytes("exit\n");
os.flush();
try {
p.waitFor();
if (p.exitValue() != 255) {
return true;
} else {
return false;
}
} catch (InterruptedException e) {
e.printStackTrace();
return false;
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
source
share