title: Android grant application root access in order to open socket on port < 1025
body: <p>In order to open a socket on a port &lt; 1025 i need root access. Exactly how do i give my application this priviledge? I know i can run the su command in a shell to get root access,  but is that all i need to do to open a socket on a port &lt; 1025? Or do i need to run some sort of command like su open socket 0.0.0.0:80 or something? I am so confused as there are such little resources out there for this. What is the purpose of google not pre-rooting all of their devices?</p>
  
  <p>Here is what i know i can do to get root access. <a href="http://www.youtube.com/watch?v=jmfvX8zvsS0&amp;list=UUk1SpWNzOs4MYmr0uICEntg&amp;index=4&amp;feature=plcp" rel="nofollow">http://www.youtube.com/watch?v=jmfvX8zvsS0&amp;list=UUk1SpWNzOs4MYmr0uICEntg&amp;index=4&amp;feature=plcp</a></p>
  
  <p>EDIT: I just wrote this:</p>
  
  <pre><code>public class RootTestActivity extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      Button button = (Button)findViewById(R.id.button);
      button.setOnClickListener(new OnClickListener() {
  
          public void onClick(View v) {
              String cmds[] = {"su", "-c", "ls /system/app"};
              Shell shell = new Shell();
              String text = shell.sendShellCommand(cmds);
              TextView textView = (TextView)findViewById(R.id.textView);
              textView.setText(text);
              try {
                  ServerSocket socket = new ServerSocket(80);
                  Log.d("Root", "Opened socket on port 80!!!");
              }catch(Exception e) {
                  Log.d("Root", "Failed to open socket on port 80!!!");
                  e.printStackTrace();
              }
          }
  
      });
    }
  }
  </code></pre>
  
  <p>What this does is it runs the commands su, -c, and then ls /system/app when a button is clicked. Then it gets the output and shows it on a textview (which actually works. I got the su prompt and selected accept and it listed everything in /system/apps/). But then after that i attempt to open a socket on port 80 and it still says Permission Denied. The application has root access, but still cannot open the socket! In the logcat it printed out "Failed to open socket on port 80!!!" as i told it to do when the exception is caught. What can i do to open the socket on port 80 without permission denied?</p>