In my Android Application, in Kotlin, I start a thread which launch a NodeJS server. On non rooted device, Node listen on port 8080. It works fine. I'd like that on rooted device Node listen on port 80. Here is what I do :
I tried to acquire su right, so that my thread can listen at port 80. It fail, my Threah crash with : Error: listen EACCES: permission denied 0.0.0.0:80 I expect my Thread to have the right to liste to port 80 since my App get su
Apps on Android (respectively the app's main process) never run with root permissions. On rooted devices apps can start other non-ui processes in background with root permissions using su
.
An app having "su permissions" means that the root manager - Magisk in your case - allows your app to perform actions using the su
binary not that it will run with root permissions.
Permissions are applied to processes not threads. Therefore it is impossible to start a thread (e.g. of an app) with root permissions.
The easiest way to achieve opening port 80 would be running the process that opens the port with su. If the process itself does not drop root permissions after opening the port that this may cause a security threat to your phone. Alternatively use a tool like socat
running with root permission to open up the port and forward packets to the actual service e.g. running on port 8080 without root permissions. Alternatively forwarding may also be done using iptables.