I am running my code on a rooted Nexus, Android 6.0.1, with my apk as a system app (i.e. android:sharedUserId="android.uid.system"
in system/priv-app
. Since it is a system app, and I am rooted, I do not understand why I cannot run my su
commands. Let me iterate, I can run su
and rm -f /data/data/com.google.android.gms/shared_prefs/adid_settings.xml
through an adb shell
successfully.
This is what I am trying to run:
public void reset_GAID_3() throws Exception {
try{
Process su = Runtime.getRuntime().exec("su");
DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
outputStream.writeBytes("rm -f /data/data/com.google.android.gms/shared_prefs/adid_settings.xml
");
outputStream.flush();
outputStream.writeBytes("exit
");
outputStream.flush();
su.waitFor();
outputStream.close();
}catch(IOException e){
throw new Exception(e);
}catch(InterruptedException e){
throw new Exception(e);
}
}
There error is occuring at:
outputStream.writeBytes("rm -f /data/data/com.google.android.gms/shared_prefs/adid_settings.xml
");
Here is the stacktrace:
Caused by: android.system.ErrnoException: write failed: EPIPE (Broken pipe)
at libcore.io.Posix.writeBytes(Native Method)
at libcore.io.Posix.write(Posix.java:271)
at libcore.io.BlockGuardOs.write(BlockGuardOs.java:313)
at libcore.io.IoBridge.write(IoBridge.java:493)
at java.io.FileOutputStream.write(FileOutputStream.java:186)?
at java.io.OutputStream.write(OutputStream.java:82)?
at java.io.DataOutputStream.writeBytes(DataOutputStream.java:156)?
at com.example.adtry3.MainActivity.reset_GAID_3(MainActivity.java:363)?
at com.example.adtry3.MainActivity.reset_GAID_button(MainActivity.java:336)?
at java.lang.reflect.Method.invoke(Native Method)?
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:409)?
at android.view.View.performClick(View.java:5204)?
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:992)?
at android.view.View$PerformClick.run(View.java:21156)?
at android.os.Handler.handleCallback(Handler.java:739)?
at android.os.Handler.dispatchMessage(Handler.java:95)?
at android.os.Looper.loop(Looper.java:148)?
at android.app.ActivityThread.main(ActivityThread.java:5422)?
at java.lang.reflect.Method.invoke(Native Method)?
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)?
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)?
My understanding is that I have an error because I am not executing the rm
in a superuser instance, but I thought that I am. I attempted to change it to a single command:
su -c 'rm -f /data/data/com.google.android.gms/shared_prefs/adid_settings.xml'
This did not work. Any ideas where I am going wrong? Thanks.
question from:
https://stackoverflow.com/questions/65909973/how-do-i-fix-java-io-ioexception-write-failed-epipe-broken-pipe-when-i-am-ro 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…