AnsweredAssumed Answered

Android 4.4.2/Kernel 3.0.35 APP Runtime.exec("su") issue

Question asked by Rudolph Hsueh on Jul 20, 2015

Hi all,

     I'm working about execute special system command which have to get root permission.

 

In my app, I used the following code to get root permission:

Running command with su in android application

Process p = Runtime.getRuntime().exec("su");  // <--always broken

OutputStream os = p.getOutputStream();

DataOutputStream dos = new DataOutputStream(os);

dos.writeBytes("...");

dos.writeBytes("...");

dos.writeBytes("exit\n");

dos.flush();

dos.close();

 

 

When I want to get root from android app, it always show me the following message:

logcat message

01-02 00:04:45.260: W/AudioTrack(2735): AUDIO_OUTPUT_FLAG_FAST denied by client due to mismatching sample rate (48000 vs 44100)

01-02 00:04:45.280: W/System.err(4612): java.io.IOException: write failed: EPIPE (Broken pipe)

01-02 00:04:45.280: W/System.err(4612):     at libcore.io.IoBridge.write(IoBridge.java:455)

01-02 00:04:45.280: W/System.err(4612):     at java.io.FileOutputStream.write(FileOutputStream.java:187)

01-02 00:04:45.280: W/System.err(4612):     at java.io.OutputStream.write(OutputStream.java:82)

01-02 00:04:45.280: W/System.err(4612):     at java.io.DataOutputStream.writeBytes(DataOutputStream.java:156)

01-02 00:04:45.280: W/System.err(4612):     at com.example.testgetroot.MainActivity$1.onClick(MainActivity.java:64)

01-02 00:04:45.280: W/System.err(4612):     at android.view.View.performClick(View.java:4438)

01-02 00:04:45.280: W/System.err(4612):     at android.view.View$PerformClick.run(View.java:18422)

01-02 00:04:45.280: W/System.err(4612):     at android.os.Handler.handleCallback(Handler.java:733)

01-02 00:04:45.280: W/System.err(4612):     at android.os.Handler.dispatchMessage(Handler.java:95)

01-02 00:04:45.280: W/System.err(4612):     at android.os.Looper.loop(Looper.java:136)

01-02 00:04:45.280: W/System.err(4612):     at android.app.ActivityThread.main(ActivityThread.java:5017)

01-02 00:04:45.280: W/System.err(4612):     at java.lang.reflect.Method.invokeNative(Native Method)

01-02 00:04:45.280: W/System.err(4612):     at java.lang.reflect.Method.invoke(Method.java:515)

01-02 00:04:45.280: W/System.err(4612):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)

01-02 00:04:45.280: W/System.err(4612):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)

01-02 00:04:45.280: W/System.err(4612):     at dalvik.system.NativeStart.main(Native Method)

01-02 00:04:45.280: W/System.err(4612): Caused by: libcore.io.ErrnoException: write failed: EPIPE (Broken pipe)

01-02 00:04:45.280: W/System.err(4612):     at libcore.io.Posix.writeBytes(Native Method)

01-02 00:04:45.280: W/System.err(4612):     at libcore.io.Posix.write(Posix.java:202)

01-02 00:04:45.280: W/System.err(4612):     at libcore.io.BlockGuardOs.write(BlockGuardOs.java:197)

01-02 00:04:45.280: W/System.err(4612):     at libcore.io.IoBridge.write(IoBridge.java:450)

 

 

I found some methods to solve it. But it still not work.

 

 

Method 1: Change the /system/xbin/su permission

adb shell mount -o rw,remount  /system 

adb push su /system/xbin/su 

adb shell chmod 06755 /system 

adb shell chmod 06755 /system/xbin/su

 

 

Method 2: Another exec command, but I think it doesn't work before I try it. And it in my expectancy. It doesn't work...
Process p = Runtime.getRuntime().exec("su -c sh");

 

 

Method 3: Somebody suggest me to comment out /system/extras/su/su.c like the following code:

/* Comment out these

myuid = getuid();

if (myuid != AID_ROOT && myuid != AID_SHELL) {

      fprintf(stderr,"su: uid %d not allowed to su\n", myuid);

      return 1;

}

*/

 

 

 

But method 3 isn't work, too.

 

I'm not sure why I can't get the root permission in eng mode even if I already have su command.

 

I have others platform, MTK and TI. They are working about  Process p = Runtime.getRuntime().exec("su");

 

I compared what different with freescale. But I'm not getting any acquisition.

 

May I have any suggestions to figure out this issue... Thank you.I would be appreciated you.

 


Best regards,

Rudolph

Outcomes