没有root权限无法在android上运行iperf3

我需要制作运行 iperf3 库的 android 应用程序,因此我使用 android-ndk-r20 编译了“iperf3”,并进行了更改


iperf_api.c


char buf[] = "/tmp/iperf3.XXXXXX";我已经替换为char buf[] = "/data/local/tmp/iperf3.XXXXXX";,弄清楚如何将其与我的 Android 应用程序打包并运行。但我不知道如何在没有“su”(root)权限的情况下运行它。


运行良好的代码:


ArrayList<String> commandLine = new ArrayList<String>();

commandLine.add("su");

commandLine.add("-c");

commandLine.add(getApplicationContext().getApplicationInfo().nativeLibraryDir+"/libiperf3.so -c speedtest.hostkey.ru -t 10 -i 5 -P 3 -d");

Process process = Runtime.getRuntime().exec(commandLine.toArray(new String[0]));

它与“su”配合得很好,但我需要让它在没有 root 的情况下工作。当我尝试相同的代码但将“su”替换为“sh”时,我收到此错误:


iperf3: error - unable to create a new stream: Permission denied

我不知道如何让它工作,Google Play 商店中有一些应用程序在没有 root 权限的情况下使用 iperf3,所以这是可能的。我做错了什么?


蓝山帝景
浏览 88回答 2
2回答

慕无忌1623718

我想出了如何让它发挥作用。在编译“iperf3”之前,您需要更改“iperf_api.c”中的以下行char&nbsp;buf[]&nbsp;=&nbsp;"/tmp/iperf3.XXXXXX";到char buf[] = "/data/data/your.package.name/cache/iperf3.XXXXXX";&nbsp;并且效果很好!我希望我帮助了某人。

婷婷同学_

当您将以下任何环境变量设置为可写目录(即cacheDir)时,它也可以工作:TMPDIR或TEMP或TMP例如:&nbsp;Os.setenv("TEMP", CACHE_DIR, true)在函数中检查临时目录iperf_api.c&nbsp;iperf_new_stream。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java