简体   繁体   English

如何修复 java.io.IOException: write failed: EPIPE (Broken pipe) 当我扎根时?

[英]How do I fix java.io.IOException: write failed: EPIPE (Broken pipe) when I am rooted?

I am running my code on a rooted Nexus, Android 6.0.1, with my apk as a system app (ie 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.我在根 Nexus Android 6.0.1 上运行我的代码,我的 apk 作为系统应用程序(即android:sharedUserId="android.uid.system" in system/priv-app 。因为它是一个系统应用程序,并且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成功地。

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\n");
            outputStream.flush();

            outputStream.writeBytes("exit\n");
            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\n");出现错误: outputStream.writeBytes("rm -f /data/data/com.google.android.gms/shared_prefs/adid_settings.xml\n");

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.我的理解是我有一个错误,因为我没有在超级用户实例中执行rm ,但我认为我是。 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.谢谢。

Not quite the best answer in the world, but I fixed it by removing the su instance and running it through a ProcessBuilder instead.不是世界上最好的答案,但我通过删除su实例并通过ProcessBuilder运行它来修复它。

public void reset_GAID_3() throws Exception {
        ProcessBuilder su = new ProcessBuilder("rm", "-f", "/data/data/com.google.android.gms/shared_prefs/adid_settings.xml");
        try{
            Process pc = su.start();
            System.out.println("Ran SU cmd");
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("Failed SU cmd");
        }

    }

I am sure there was a problem with how the code was being executed after the su command, but this is a way around it.我确信在su命令之后执行代码的方式存在问题,但这是一种解决方法。 Since the su is what seemed to be causing the problem, I simply removed it.由于su似乎是导致问题的原因,我只是将其删除。 Removing it means I could use a simple ProcessBuilder to get what I needed done.删除它意味着我可以使用一个简单的ProcessBuilder来完成我需要的工作。

Why did this still work?为什么这仍然有效? Since this apk is located in system/priv-app , and it has android:sharedUserId="android.uid.system" in the Manifest, this means it's already operating with root permissions, so it would be redundant to use su .由于此 apk 位于system/priv-app中,并且在 Manifest 中有android:sharedUserId="android.uid.system" ,这意味着它已经以 root 权限运行,因此使用su将是多余的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有拍摄意图的Android FileProvider给出java.io.IOException:写入失败:EPIPE(管道损坏) - Android FileProvider with photo take intent gives a java.io.IOException: write failed: EPIPE (Broken pipe) java.io.IOException: 管道损坏 - java.io.IOException: Broken pipe PipedInputStream - 如何避免“java.io.IOException:Pipe broken” - PipedInputStream - How to avoid “java.io.IOException: Pipe broken” Why did I get “Error commiting response java.io.IOException: Broken pipe at sun.nio.ch.FileDispatcher.write0(Native Method)” with SSL - Why did I get “Error commiting response java.io.IOException: Broken pipe at sun.nio.ch.FileDispatcher.write0(Native Method)” with SSL 如何修复/避免java.io.IOException:套接字读取失败? - How to fix/avoid java.io.IOException: Socket read failed? 避免日志充满 java.io.IOException: Broken pipe - Avoid logs full of java.io.IOException: Broken pipe 为什么在此循环中收到java.io.IOException? - Why am I receiving a java.io.IOException in this loop? Android错误:写入失败:EPIPE(管道断开) - Android error: write failed: EPIPE (Broken pipe) 在android/java中调用createNewFile()时,为什么会出现:java.io.IOException: No such file or directory - When calling createNewFile() in android/java, why do I get: java.io.IOException: No such file or directory 提交响应 java.io.IOException 时出错:sun.nio.ch.FileDispatcher.write0(Native Method) 处的管道损坏 - Error commiting response java.io.IOException: Broken pipe at sun.nio.ch.FileDispatcher.write0(Native Method)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM