没有root权限无法在android上运行iperf3 [英] Can't run iperf3 on android without root permission

查看:46
本文介绍了没有root权限无法在android上运行iperf3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要制作运行 iperf3 库的 android 应用程序,所以我使用 android-ndk-r20 编译了iperf3",并在

I need to make android application that run iperf3 library, so i have compiled "iperf3" using android-ndk-r20 with changes made in

iperf_api.c

iperf_api.c

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

char buf[] = "/tmp/iperf3.XXXXXX"; I've replaced with char buf[] = "/data/local/tmp/iperf3.XXXXXX";, figured it out how to package it with my android application and run. But I don't know how to run it without "su" (root) permissions.

运行良好的代码:

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"时,我收到此错误:

It works well with "su", but I need to made it work without root. When I try same code but with "su" replaced by "sh" I get this error:

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

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

I don't know how to made it work, there is some applications that are using iperf3 in Google Play Store without root permissions, so it is possible. What I'm doing wrong?

推荐答案

我想出了如何让它发挥作用.在编译iperf3"之前,您需要更改iperf_api.c"中的后续行

I figured it out how to make it work. Before compile "iperf3" you need to change followed line in "iperf_api.c"

char buf[] = "/tmp/iperf3.XXXXXX";

to char buf[] = "/data/data/your.package.name/cache/iperf3.XXXXXX";它工作正常!我希望我帮助了某人.

to char buf[] = "/data/data/your.package.name/cache/iperf3.XXXXXX"; And it works fine! I hope I helped someone.

这篇关于没有root权限无法在android上运行iperf3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆