tags:

views:

48

answers:

1

I'm trying to create a ServerSocket on a port below 1024.

Obviously, this is restricted to root access only.

But I'm struggling on getting the right permissions for my app.

I'm using this code, for example, to test if I have root access (or trigger the dialog)

But it still doesn't let me ServerSocket work.

AFAIK, the process that is created with the SU command has the root access, not my app. How do I get root access into 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;
        }
    }
A: 

Afaik you cannot open a port below 1024 under *nix systems if you're not root...

Arman