This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Android JelleyBean Superuser Access

Hello All,

Greetings. I have just started explorling and learning to develop Android Applications. I have AM335x CPU Module and Development board that I recently purchased from MYIRTECH ( http://wwww.myirtech.com ) They have provided me with Kernel Source Code Android JB 4.2, RootFS and Uboot along with instructions to compile and load it to the NAND. Everything works fine except a few for which I am unable to get enough support from them and I finally landed here to seek some advise from experts.

Actually the Development baord has Ethernet Jack through which I can connect it to my LAN. When I asked them about changing the IP address, they suggested me to use the serial console (UART1) adb and use the IFCONFIG command to set the IP address. It works perfectly, but I actually want it to be changed from the android application. When I searched the internet, I learned about executing shell commands and I did something as indicated below, but it did not work out. I guess the application must not be having SU access. When I again asked them they suggested me to replace the SU binary with the binaries provided with Superuser.APK , use chmod in init.rc etc.....I did so, but ended up with no luck. I dont have any recompiled SU binaries that will allow me to execute shell commands.  Please advise me on this. I am desperately trying this for days. Please advise.

Here is the piece of code that I tried to execute from android app.

private static void changeSystemTime(String year,String month,String day,String hour,String minute,String second){
   
    try {
        Process process = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(process.getOutputStream());
        String command = "ifconfig 192.168.2.2 eth0 UP " +"  \n";
       // Log.e("command",command);
        os.writeBytes(command);
        os.flush();
        os.writeBytes("exit\n");
        os.flush();
        process.waitFor();
        Toast.makeText(mContext, "All Ok", Toast.LENGTH_LONG).show();
    } catch (InterruptedException e) {
        e.printStackTrace();
        Toast.makeText(mContext, "Error", Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        e.printStackTrace();
        Toast.makeText(mContext, "IO Exception", Toast.LENGTH_LONG).show();
    }
   
   
}
  
  • Hello,

    It seems you inverted the IP address and the interface, it should be "ifconfig eth0 192.168.2.2 UP" and not "ifconfig 192.168.2.2 UP". Which message the toast returns?
    You can also try to add to your application's manifest:
    android:sharedUserId="android.uid.system"

    Another possibility is to try this code:

    Java.Lang.Runtime proc = Java.Lang.Runtime.GetRuntime();
    proc.Exec(new String[]{"su", "-c", "ifconfig eth0 192.168.2.2 UP"});